Lesson 117 – Complete 2020 Web Development Bootcamp

Lesson 117 – Functions Part 3 – Outputs and Return Values

This is my code from this lesson on using functions to get outputs and returns.

function getMilk(money, bottleCost) {   
  //var bottleCost = 1.5
  //var totalBottles = Math.floor(money / bottleCost)
  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");
  console.log ("Buy " + calcBottles(money, bottleCost) + " bottles of milk.")
  //console.log("You have $" + money + ". You can buy " + totalBottles + " 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, 1.5);
}

function calcBottles(startingMoney, bottleCost) {
    var totalBottles = Math.floor(startingMoney / bottleCost);
    return totalBottles;
}

function calcChange(startingMoney, bottleCost) {
    var change = startingMoney % bottleCost;
    return change;
}

console.log("Hello Sir, here is your " + getMilk(10, 3) + " change.");