Function parameter question


In the code

var orderCount = 0;
function takeOrder(topping, crustType) {
console.log('Order: ’ + crustType + ’ crust topped with ’ + topping);
orderCount = orderCount + 1;
function getSubTotal(itemCount) {
return itemCount * 7.5;
takeOrder(‘bacon’, ‘thin’);
takeOrder(‘pepperoni’, ‘regular’);
takeOrder(‘pesto’, ‘thin’);

How does the parameter (itemCount) get it’s value of three In the function getSubTotal? I mean, how does itemCount know what it is doing? How does it ‘know’ what constitutes an ‘item’ , for example?


You gave it that number.
Parameters are you telling a function it will be handed something. You write in the parenthesis what it is being handed for your own readabilities sake. In this case youre telling the function "Im going to hand you a certain number of items, take that number multiply it by 7.5 and give it back.

check out this line console.log(getSubTotal(orderCount));
You told the function to take however many items there are in orderCount and multiply it by 7.5
Remember that you determined how big orderCount was with the takeOrder function.

See how everything is coming together now? Functions hand each other data and manipulate it.


Thank you for your reply. I am stupid.


Nope, you’re learning. Which is the smartest thing of all. /cliche but true


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