Why does my orderCount = 0?


#1

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');
console.log(getSubTotal(orderCount));

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?


#2

if we remove the shorthand we get:

orderCount = ordercount = orderCount + 1;

which doesn’t seem right


#3

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


#4

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


#5

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

orderCount++

Or it could be:

orderCount = orderCount + 1

Got it, thanks!


#6

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


#7

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