Question about the return statement


#1

Hey guys!
Why do I have to use the the itemCount parameter instead of the orderCount. For me it doesn't make sense to use the itemCount parameter because I haven't defined this parameter yet.

Thanks for the help! :slight_smile:

var orderCount = 0;
function takeOrder (topping , crustType) {
console.log (“Order:“ +crustType+ “crust topped with“ +topping);
orderCount = orderCount + 1;
}
function getSubTotal (itemCount) {
** turn itemCount * 7.5;
}

takeOrder (“bacon“ , “thin“);
takeOrder (“peperoni“ , “regular“);
takeOrder (“pesto“ , “thin“);

console.log (getSubTotal (orderCount) );


#2

you don't define parameters, function parameters are placeholders until you call the function, which you do here:

console.log (getSubTotal (orderCount) );

so the value of orderCount (3 in this case) is passed along to the function parameter itemCount.