Help with a global variable inside a function


#1



It doesn`t, I wanted to ask you about a global variable in the body of the first function: orderCount = orderCount+1;. The question goes, how do I make that global variable a 3rd parameter of the function and not a global one? whatever I try, I either get NaN or i get all of the takeOrder(s) but getSubTotal is 0 (writing in Notepad++, running the "code" in node.js command prompt). Ty in advance.


var orderCount = 0;

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

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", "Fat");
takeOrder("cheese", "Burned");
console.log(getSubTotal(orderCount));
console.log(getTotal());


#2

You'd add a third parameter and supply three arguments to it when calling it


#3

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