orderCount


#1

I was just wondering: why do we need to add orderCount into the arguements every time we call getSubTotal ? Could someone explain the code in detail to me? Everything makes sense to me except the part where we keep repeating orderCount.

var orderCount = 0;

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

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

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

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

takeOrder('ham', 'thick');
takeOrder('salami', 'deepdish');
takeOrder('margherita', 'thin');

console.log(getTotal());

`


#2

You pass orderCount (amount of pizzas ordered) as an argument to this function to get ... well, sub-total :slight_smile:
Within this function the value you pass becomes known as itemCount and you multiply it by the price of one piece.


#3

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