Need some help understanding something with functions


#1



Hello,

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


#2

but right here:

itemCount is a parameter...


#3

Wrong wording my bad...

How does it know to add up the takeOrder functions?


#4

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?


#5

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


#6

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.


#7

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:


#8

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


#9

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.


#10

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