Instructions in green, but the code fails in run


I’m on Javascript functions, 5/10

My code:

var orderCount = 0;

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

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

takeOrder('chicken', 'mushrooms');
takeOrder('eggs', 'mushrooms');
takeOrder('milk', 'mushrooms');


A screenshot:



ReferenceError: orderCount is not defined.

You declared orderCount in the global scope: var orderCount = 0;
So, there, no problem, you had to do this.

But then you’ve re-declared another orderCount variable that has block scope, using const.
That const orderCount only lives within the takeOrder function. It doesn’t read the global variable that you defined on line 1.

You need to refactor const orderCount = (orderCount + 1) so that it increments the global variable on line 1.

Scope was explained in earlier exercises. Any ideas how you might achieve this? :slight_smile:

Hint: you need to increment orderCount by one. There’s a short form to achieve this.


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