Why does my orderCount = 0?


In the ‘Return’ exercise, I passed the task using this code:

let orderCount = 0
const takeOrder = (topping, crustType) => {
  console.log('Order: ' + crustType + ' pizza topped with ' + topping);
  orderCount = orderCount++;
let getSubTotal = (itemCount) => {return itemCount * 7.5};

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

However, when I ran the code, orderCount remained at 0, as did itemCount when I believe orderCount and itemCount should have been 3 and 22.5 respectively.

Can anyone tell me what’s going on? If I’ve done the exercise wrong, why did it seemingly pass me?


if we remove the shorthand we get:

orderCount = ordercount = orderCount + 1;

which doesn’t seem right


Ok, why didn’t the codecademy course tell me it was wrong then?


Seems you found a corner case which isn’t caught by the exercise. I suppose the exercise did a regex and found orderCount++ present.


Right, ok so that last line of the function could be either:


Or it could be:

orderCount = orderCount + 1

Got it, thanks!


or orderCount += 1, but yea, make sure to use a shorthand correctly :slight_smile:


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