5/10 - Return - Passing In Parameters


#1

So I get the concept of passing in parameters but… I don’t understand this…

let orderCount = 0;

const takeOrder = (topping, crustType) => {
  orderCount++;
  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;
};

How does the itemCount parameter “know” that there are 3 items? I cannot see the link between the takeOrder data and the parameter in getSubTotal?

It doesn’t even matter if I change the name from itemCount to something completely different? It doesn’t matter if the data is right above or even below the function?

What am I missing?


#2

there isn’t yet, a function parameter (itemCount) is only a placeholder until your function call. If you add a function call and pass orderCount as argument, then itemCount knows


#3

Ok well I’m glad you said that!

I get it now thank you…


#4

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