Sanity check requested


#1

This code was my solution for the “Return” exercise. Initially, I used “var” instead of “let”, but since they are outside of any block they both had global scope. All the same, I changed it to “let” as part of the debugging process, because for the life of me I couldn’t figure out why I was getting the “Declare a variable named orderCount set equal to the number 0.” error.

The code appears to be working. I wrote this in a way that seemed quite natural to me as a transitioning C++/Java programmer.

let orderCount = 0;

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

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

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

console.log(getSubTotal(orderCount));

#2

Hey!

I have absolutely no experience at all with coding so I don’t want to come across as ignorant or arrogant but I’m currently at the same part of the course as you. It’s very specifically asking for the ''let orderCount = 0;" code to be placed above the “takeOrder()” part.

This is what my code looks like in comparison:

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

let orderCount = 0;

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

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

console.log(getSubTotal(orderCount));

edit: So the reason you get the error message is because you have “let orderCount = 0;” on line 1 when it should be on line 6 (or 5) when you take into consideration that the two lines before “const takeOrder…” are removed.


#3

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