Need some help understanding something with functions


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

The code provided works as expected in the functions section. However I need some help in understanding how the itemCount is actually being calculated as it is not a parameter in any of the functions. Can someone explain this to me please?


var orderCount = 0;
function takeOrder(topping, crustType){
orderCount = orderCount + 1;
console.log(‘order:’ + ’ ’ + crustType + ’ ’ + 'topped with ’ + ’ ’ + topping);

function getSubTotal(itemCount){
return itemCount * 7.5;

function getTax() {
return getSubTotal(orderCount) * 0.06;

function getTotal() {
return getSubTotal(orderCount) + getTax();
takeOrder(‘pepperoni’, ‘thin crust’);
takeOrder(‘pepperoni’, ‘thin crust’);

<do not remove the three backticks above>

but right here:

itemCount is a parameter…

Wrong wording my bad…

How does it know to add up the takeOrder functions?

Also though, this is the last lesson to the module, so anything would have passed. I’m wondering if you don’t understand the code you wrote? This was extra work not needed. What exactly are you having trouble with?

You’re right, I see what you’re saying… I’m thinking maybe itemCount needs to be orderCount instead.

Changing itemCount to orderCount works. As long as I know I’m not completely crazy, but the lesson instructions in the 5th lesson definitely clearly say to create the parameter as itemCount lol.

I’m sorry! I don’t know why it’s like that. I’m glad you got past it, but I’m sorry. I just looked at the instructions that’s so weird. :unamused:

No worries! I just wanted to make sure I wasn’t crazy. I’ll submit a bug report on the instructions. :slight_smile:

Great idea. :slight_smile: Normally the interface is pretty good, but in my opinion, the Learn JavaScript one is pretty lousy most of the time.

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