Functions 5/7


#1

Continuing from https://discuss.codecademy.com/t/functions-5-7/73532/9...
So I have the same question. The code is working but I still didn't get why /how "orderCount" became "itemCount"
so the full code is:

var orderCount = 0;

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

function getSubTotal(itemCount) {
return itemCount * 7.5;
}
function getTax(){
return getSubTotal(orderCount)*0.06;
}
function getTotal(){
return getTax()+getSubTotal(orderCount);
}

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

console.log(getSubTotal(orderCount));
console.log(getTotal());

So we assume that itemCount=3 because we made takeOrder function run three times. But how JS sees that? we didn't use "itemCount" anywhere in the code before. Ok, let's look further:
Later in "function getTax" and "function getTotal" we use "getSubTotal" function to make further calculations we need, but look: we don't write "getSubTotal (itemCount)"(how it was written on our getSubTotal function that we are using here), we write "getSubTotal(orderCount)"! why? Are "orderCount" and "itemCount" interchangeable? if so, why we can't just use "orderCount" everywhere?
I hope somebody can explain it to me!
Thank you!


Functions 5/7
#2

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