Return II - What am I doing wrong?


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

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

https://www.codecademy.com/courses/learn-javascript-functions/lessons/functions/exercises/return-ii?action=lesson_resume&course_redirect=introduction-to-javascript

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

I don’t understand exactly what my problem is. The exercise is technically allowing me to continue even though the following error messaged appeared.

Order: thin crust pizza topped with mushroom
Order: whole wheat pizza topped with spinach
Order: brooklyn style pizza topped with pepperoni
/home/ccuser/workspace/javascript_101_Unit_3_v3/pizza.js:17
return getSubTotal(orderCount) * 0.06;
^

TypeError: getSubTotal is not a function
at getTax (/home/ccuser/workspace/javascript_101_Unit_3_v3/pizza.js:17:8)
at getTotal (/home/ccuser/workspace/javascript_101_Unit_3_v3/pizza.js:21:36)
at Object. (/home/ccuser/workspace/javascript_101_Unit_3_v3/pizza.js:24:13)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)

Here’s the code I used. What seems to be the problem?


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

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

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

console.log(getTotal());

#2

your getTax function:

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

why does it have getSubTotal parameter? It shouldn’t, which also explains the error given you call getTax without argument, so the parameter has no value


#3

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