<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Not incorrect or error message, I just wondered where the itemCount comes from in the code, as it seems to appear out of nowhere and just dissapears(see attached code). I’ve tried messing around with it, however this is the only configuration that seems to work for me.
```
var orderCount = 0
function takeOrder(topping, crustType) {orderCount= orderCount + 1;
console.log('Order: ’ + crustType + ’ crust topped with ’ + topping);
}
function getSubTotal(itemCount) {return itemCount * 7.5}
itemCount is a function parameter, parameters are defined when you define a function:
function exampleFunction(exampleParameter){
console.log(exampleParameter);
}
parameters (in this example exampleParameter) are placeholders until a value/argument is supplied at function call:
// function deceleration with parameter exampleParameter
function exampleFunction(exampleParameter){
console.log(exampleParameter);
}
// function call with argument
exampleFunction("hello world!");
the same logic applies to your function parameter (itemCount)
so itemCount is a placeholder until you call the function:
console.log(getSubTotal(orderCount))
now orderCount get passed into the function parameter
I had the same question. Since I don’t particularly understand the previous comment that is undoubtedly correct, I’ll just share what I did and my understanding.
I struggled finding the definition for “itemCount” thinking it needed to be defined before using it. I was wrong. It is (as was stated) a placeholder. I replaced it with “popsicle” in both spots and it had the same output. It seems as though the parameter is a variable that isn’t defined until after it is used.
My understanding now is that you do not need to define parameters prior to using them in the same way that you would use a variable. So, “itemCount” could be just about any previously undefined word/phrase that gets replaced once it is plugged into “console.log(getSubTotal(orderCount))” as “orderCount” because of the way it is nested into the getSubTotal function.
If this is confusing, incomplete, or even wrong, hopefully someone more experienced will clarify!
So I’m gonna piggy back off of @stetim94 here, cause even after reading this I was still confused (read: frustrated) over the whole itemCount vs orderCount. I was pretty sure the two were mistakenly being used interchangeably.
What frustrated me was the fact that at the end of the code where you call getSubTotal() inside the console.log()…i was typing
console.log(getSubTotal(3));
yes, I was manually entering the number of orders in the function call. I was like “this is stupid if I have to tell the program how many orders there are! I thought that’s why we defined orderCount, to automatically add one every time we called the takeOrder function.”
and it sorta just clicked (after like the third time i read over it. lol)
orderCount IS calculated when you call takeOrder()! you just have to use that as your parameter when calling getSubTotal()
I hope this may have help even just one person…i tell you, itemCount vs orderCount…they could come up with better variable names or at least explained that they ARE meant to be named as such.
I’m uh…not sure what you are saying that’s different from what I said.
You call the function takeOrder() and the value of orderCount is increased by 1 (ultimately changing the value of orderCount to be the same number of time you call takeOrder()).
I agree with @pshock13 last statement. My code worked but I didn’t understand how itemCount was being defined. If @codecademy had explained the placeholder bit in the lesson I wouldn’t have sat there wondering how on earth I got it to work without defining itemCount!
How come no one wonders where topping and crustType are defined? Function parameters are defined when you defined a placeholder, and then serve as placeholder until the function is called and arguments are provided for the parameters
itemCount is a parameter of a function. The argument you are passing is the value stored in the orderCount variable.
I got stuck with this thinking itemCount should have been a defined variable, and though that the exercise author meant to type orderCount. Substituting itemCount with orderCount worked (where itemCount did not work - it returned 0).
I must have had a typo or something because as soon as I did that and read through this thread I realised either should work (and they do).