Currently delving into the world of JavaScript functions and stumbled upon this code snippet with the following output:
Output: "buy 3 bottles of milk" "Hello master, here is your 0 change"
function getMilk(money, costPerBottle) {
console.log("buy " + calcBottles(money, costPerBottle) + " bottles of milk");
return calcChange(money, costPerBottle);
}
function calcBottles(startingMoney, costPerBottle) {
var numberOfBottles = Math.floor(startingMoney / costPerBottle);
return numberOfBottles;
}
function calcChange(startingAmount, costPerBottle) {
var change = startingAmount % costPerBottle;
return change;
}
console.log("Hello master, here is your " + getMilk(6, 2) + " change");
Struggling to grasp the significance of "startingMoney" and "startingAmount" in this context. Plus, curious about how it calculates the number of bottles.