Question on this code for 6/10 Return II



Hey all, so I finally got this code correct and passed the exercise, however I’m looking for a better understanding of one thing that I’m confused on. Why exactly do I need to include the argument “orderCount” for the getSubTotal functions when I call them in my “getTax” and “getTotal” blocks. I’m confused because I don’t need an argument passed into the getTax function, so why is it needed in the getSubTotal function? just specifically in my code for the getTax and getTotal blocks.

let orderCount = 0;

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

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

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

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

takeOrder('mushrooms', 'thin crust');
takeOrder('pepperoni', 'seasoned crust');
takeOrder('xtra cheese', 'cheese stuffed crust');

  `Subtotal: $${getSubTotal(3).toFixed(2)}`);

  `Total with tax: $${getTotal().toFixed(2)}`);


lets do an example, here are two functions:

const firstExample = () => {
    console.log("no parameter so just logging pointless string to console");
const secondExample = (exampleParameter) => {
    console.log(`the value of the parameter is: ${exampleParameter}`);

the first function doesn’t have a parameter. As such, when i call the function i don’t need to supply an argument:


however, the second function does have a parameter, so it needs an argument:

// function declaration with parameter exampleParameter
const secondExample = (exampleParameter) => {
    console.log(`the value of the parameter is: ${exampleParameter}`);
// function call with string argument
secondExample('hello world');

if we do not supply an argument at function call, the value of the parameter would be undefined:

const secondExample = (exampleParameter) => {
    console.log(`the value of the parameter is: ${exampleParameter}`);

which is something we do not want for our pizza program.

normally, as a programmer you decide if your function should or shouldn’t parameters, at the moment the exercises take this decisions for you

important to understand: functions only execute when called, as such, a function parameter is a placeholder until the parameter gets its value from argument at function call

hope this helps :slight_smile:


Yes, that definitely makes more sense! I feel like I probably should have realized that. Thanks!


well, what makes it confusing is having functions calling other functions, which is why i simplified it a bit for the explanation :slight_smile:

No more questions left?


No I’m good now thanks