Tells a robot home bottles of milk to get based on how much money you give
Fri Apr 21 2023 14:51:59 GMT+0000 (Coordinated Universal Time)
Saved by
@AlanaBF
#javascript
//create function
function getMilk(money, costPerBottle) {//enclose all the instructions
console.log("leaveHouse");
console.log("moveRight");
console.log("moveRight");
console.log("moveUp");
console.log("moveUp");
console.log("moveUp");
console.log("moveUp");
console.log("moveRight");
console.log("moveRight");
//numOfBottles = however much money you put in () and divide by 1.5, rounded down to the nearest whole number
console.log("buy " + calcBottles(money, costPerBottle) + " bottles of milk");
console.log("moveLeft");
console.log("moveLeft");
console.log("moveDown");
console.log("moveDown");
console.log("moveDown");
console.log("moveDown");
console.log("moveLeft");
console.log("moveLeft");
console.log("enterHouse");
return calcChange(money, costPerBottle) ;
}
function calcBottles(startingMoney, costPerBottle) {
let numberOfBottles = Math.floor(startingMoney / costPerBottle);
return numberOfBottles;
}
function calcChange(startingMoney, costPerBottle) {
let change = startingMoney % costPerBottle;
return change;
}
//call the function
console.log("Hello Alana, here is you " + getMilk(5, 1.5) + " change.");
content_copyCOPY
Comments