The Answer to the function

#1

Well, my question is why the answer of the "function getSubTotal(itemCount)" is 22.5?
Shouldn't it be 7.5?
Cause my "var orderCount =0;" is zero

``````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 getSubTotal(orderCount) + getTax();
}

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

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

#2

You have ordered three times,

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

It means value of `orderCount` is 3 which is passed as argument to `getSubTotal()` function.

itemCount * 7.5
3 * 7.5 -- > 22.5 right?

Cause my "var orderCount =0;" is zero

Look at your function ,takeOrder()

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

everytime you call `takeOrder()`, `orderCount` is incremented by 1.

#3

Thx, I got, but what's the use of "var orderCount = 0;" for?

#4

Its used here to count how many times order is made.

#5

Thx, fully understand now!

#6

There is lot to explore,when you feel like to explore take a look at this thread..

#7

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