# What does orderCount =orderCount +1 perform?

#1

var orderCount = 0;

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

function getSubTotal(orderCount) {
return orderCount * 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());

//Output
Order: thin crust topped with bacon
Order: regular crust topped with pepperoni
Order: thin crust topped with pesto
22.5
23.85

(1) In the codes above, what does orderCount = orderCount + 1; exactly perform? I know I can’t print the result ( number 22,5 and 23.85 ) without adding this code but I do not see why it is necessary and how it works.
(2) According to the instructions, the parameter of the function getSubTotal should be itemCount instead of orderCount. What is the difference? I can output the same result even if I replace itemCount with orderCount…
(3) I am sorry if it is probably a silly question, but how can this program count orders? Is it thanks to ‘orderCount =orderCount +1’ line I asked about in the question (1)?

Thank you!

#2

(1) `orderCount = orderCount + 1;` increases orderCount by 1, this way, you keep track of how many pizza’s are sold. we start of with having sold 0 pizza’s (`var orderCount = 0;`), every time someone orders a pizza, we increase the orderCount by one

(2) using orderCount as function parameter is possible, but should be avoided, its considered bad practice given you already have this name for a variable, which might confuse

#3

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