Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Giving Information to Functions

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

trying to figure this function out!!!

i am confused about 'itemCount' and 'orderCount' // const getSubTotal = (itemCount) where do we get that from? i thought orderCount shoould be used here as we set orderCount to zero at the start and it will increase depending on the no of times order function runs :/

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;
};

console.log(getSubTotal(orderCount));

const getTax = (orderCount) => {
return getSubTotal(orderCount) * 0.06;
};
const getTotal=() => {
 return getSubTotal(orderCount) + getTax(orderCount);
};
console.log(getTotal());

1 Answer

Steven Parker
Steven Parker
230,231 Points

The name "itemCount" is simply a parameter name that serves as a "placeholder" for the actual value passed in when the function is called.

Later in the program, you can see when the function "getSubTotal" is called, it is actually the variable "orderCount" that is passed as the argument.

So you were right, "orderCount" is what is actually used to calculate the sub-total.

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

Thanks steven, as always for the rescue! i have been scratching my head over it for ages, and felt like i dont even know functions yet! i get it now.Thanks