Parameters

#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
What’s wrong with my code? It returns a NaN.

It’s still very hard for me to grasp the intrinsic of how to use parameters the right way. I understand the basics of parameters but when it’s get a bit complicated like this and I need to “override” stuff I get confused…

```

let orderCount = 0;

const takeOrder = (topping, crustType) => {
orderCount++;
console.log(`Order: \${crustType} crust pizza topped with \${topping}`);
}

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

const getTax = (itemCount) => {
return (getSubTotal(itemCount) * 0.06);
}

const getTotal = () => {
return (getSubTotal() + getTax());
}

takeOrder(‘pineapple’, ‘thicc’);
takeOrder(‘pepperoni’, ‘thin’);
takeOrder(‘bacon’, ‘focaccia’);

console.log(getTotal());

``<do not remove the three backticks above>``

#2

This exercise has a combination of passing arguments to functions and using a shared state of `orderCount` directly. It’s an interesting walk through of shared state, variable scope, and functional programming.

Take a look at the function `getSubTotal()` and `getTax()`. What are they wanting in order to do their calculations?

Parameters give us the ability to make a function independent and reusable. It’s not dependent upon shared states. Why? Because you are passing in whatever dataset or value the function needs to do its work.

How do you do that? When you call (invoke) the function, you declare the arguments that you want that function to work on.

For example, this function is declaring that it wants to receive a count in order to multiple that number of items by the price of \$7.50.

Therefore, we know how to use that function and what it needs. Right? You need to pass it the count when you call it to run.

Does that make sense?

#3

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