Confusion in Functions Ex. 5 return


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I don’t understand why the function getSubTotal requires the creation of a new variable “itemCount” when it has exactly the same information as “orderCount”. Surely the variable “orderCount” could be passed in here with the same result?

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

function getSubTotal(itemCount) {
return itemCount * 7.5;

takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);


<do not remove the three backticks above>

orderCount is a global variable and can be used in both functions,itemCount is just a parameter and nothing more it can be substituted with x, y or any other name.

Is there any advantage to using a different parameter? For me, using itemCount just makes the code more confusing, when orderCount would be more logical?

Parameters can be anything you set them to be because they are only placeholders for the values you will put in your function call.itemCount and orderCount are not the same thing because orderCount is a global variable while itemCount is just a placeholder for orderCount.

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