orderCount does not increment


#1

In exercise 5/7, orderCount stays at 0. It never gave me an error message, so I only realized at the end that it was still 0. Searching the forums so far has yielded nothing.

https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return?action=lesson_resume&link_content_target=interstitial_lesson

var orderCount = 0


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

takeOrder('pizza', 'pizza');
takeOrder('fizz', 'buzz');
takeOrder('extra', 'extra crust');

function getSubTotal(itemCount)
{
  return(itemCount * 7.5);
}

console.log(orderCount)
console.log(getSubTotal(orderCount));

Running this returns to the console:

Order: pizza crust pizza topped with pizza
Order: fizz crust pizza topped with buzz
Order: extra crust pizza topped with extra crust
0
0

#2

You are really close!

The ++ operator can be used like this:

orderCount++;

This statement is the shortand for writing:

orderCount = orderCount + 1;

Change your code to one of the above, and you should get the result you’re looking for!


#3

Removing doesn’t appear to have solved the issue. Interestingly, though, switching it to + 1 seems to work just fine. Kind of a shame, considering using ++ seems a lot neater to me.


#4

The orderCount++ syntax will work if you use it like this:

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

Note that it is not

orderCount = orderCount++;

but only

orderCount++;

Hope this helps, and nice work getting it working!


#5

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