Functions 5/10 - Declare a variable named orderCount set equal to the number 0


#1

Hi Team,

I’m wondering if you can help, I keep getting the below error:

“Declare a variable named orderCount set equal to the number 0.”

Below is my code:

"let orderCount = 0;

const takeOrder = (topping, crustType) => {
_ orderCount++;_
_ console.log('Order: ’ + crustType + ’ pizza topped with ’ + topping);_
};

takeOrder(‘mushroom’, ‘thin crust’);
takeOrder(‘spinach’, ‘whole wheat’);
takeOrder(‘pepperoni’, ‘brooklyn style’);

const getSubTotal = (itemCount) => {
_ return itemCount * 7.5;_
};

console.log(getSubTotal(orderCount));"

Can anyone suggest what I am doing wrong please?


#2

seems you have too much code? at the end of your program orderCount no longer has a value of 0


#3

Hi Stetim94,

Thanks for your wuick response! Why would the var orderCount not have a value of 3 by the end of the code?


#4

it does have a value of 3, it doesn’t have a value of 0. I made a typo

anyway, having too much code can cause problem, because the exercise checks if the value of orderCount equals zero, in your case, it doesn’t


#5

I think the problem here is that you’ve completed the entire challenge and then clicked run, instead of clicking run after each task.

The second you fire off the first function, orderCount is not equal to 0, therefore the error is displayed.

I’ve just spent 5 minutes banging my head against the desk with this exact issue. Hehe!


#6

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