Pizza JS

let orderCount = 0;


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

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


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


Okay so I have a question so,

1-We wrote orderCount variable and set it equal to 0
2- Summoned a code paragraph that will interpolate strings and add +1 to orderCount every time takeOrder function called.
3- We ordered 3 pizzas (which means +3 to orderCount variable.
4- const getSubTotal = (itemCount) => { return itemCount * 7.5; };

Okay this part is the problem, I get the idea of getSubTotal function logic but where and how the ■■■■ that itemCount parameter came out from nowhere?

5-In the last line we used console log to print the results.


I see this question more often, how come no one has trouble with topping and crustType, which also come out of “nowhere”

function parameters are defined when defining the function and serve as placeholder until its gets a value (from argument at function call)

so here:


the value stored in orderCount variable get passed into function parameter (itemCount), under the hood basically this happens:

itemCount = orderCount

the moment getSubTotal is called

itemCount is a logic name for the parameter


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