Help with 3/7 of Return II in Functions tutorial


#1


Help with 5/7 of Return II in Functions tutorial

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/parameters


No error, but confused on why the tutorial did that.


var orderCount = 0;

function takeOrder(topping, crustType) {
  console.log('Order: ' + crustType + ' crust topped with ' + topping);
  orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
  return itemCount * 5;
}

function getTax(){
  return getSubTotal(orderCount) * 0.5;
}

function getTotal(){
  return getSubTotal(orderCount) + getTax();
}

takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

console.log('Before Tax $'+getSubTotal(orderCount));
console.log('Tax is $'+getTax());
console.log('After Tax $'+getTotal());

So the tutorial mentions.

Now it's time to calculate the subtotal of the pizzas. This is the perfect job for a function.

Declare a function named getSubTotal that has one parameter named itemCount.

My question is. Why is the parameter named itemCount instead of orderCount?


#2

orderCount goes up with each order. If I were to order a pizza from Pizza Hut and get 34635890345234 * 10^35232 pizzas, it will still only be one order.

You also have to think about if you're going to use the program later on with another order, after you've paid the first. Why would you want the cost of the first order added onto it?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.