Return 2: Parameters


#1

I asked for the code from codeacademy, but I still don’t understand it.

  1. Why does it say “itemCount” on lines 8-9, while everything else says “orderCount”? Why shouldn’t they be the same?
  2. Why is it that some functions DON’T need parameters?

Here is the correct way:
https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return-ii?action=lesson_resume

Here is what I did: (I made everything say orderCount, AND I added that parameter to the functions getTax and getTotal.)

var orderCount = 0;

function takeOrder(topping, crustType) {
  console.log('Order: ' + crustType + ' crust topped with ' + topping);
  orderCount = orderCount + 1;
}

function getSubTotal(orderCount) {
  return orderCount * 7.5;
}

function getTax(orderCount) {
  return getSubTotal(orderCount) * 0.06;
}

function getTotal.(orderCount) {
  return getSubTotal(orderCount) + getTax();
}


takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');

console.log(getSubTotal(orderCount));

Thanks!!!





#2

This function would work correct no matter what the variable is named.

function getSubTotal(foo) {
  return foo * 7.5;
}

That will raise a syntax error. Take out the dot.

That call should have an argument since the function takes a parameter.


#3

Thank you, Roy! I can’t believe I didn’t catch that dot.


#6