JS Functions, Return II


#1

Lesson 6, Return II - I’m trying to get the code to tally up subtotals for pizzas ordered, add the tax, and give the total. I’m not getting an error on this code but I’m not getting desired results. Code below.


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 = (orderCount) => {  
  return getSubTotal * 0.06;
};
const getTotal = () => {
   return
   getSubTotal(orderCount) + 
     getTax(orderCount);
 };
console.log(getTotal);

Console returns all pizza and topping descriptions, no subtotals and no totals, but last line is “[Function getTotal]”
??


#2

to execute a function you need: functionName();, you miss the parentheses.

also, return + the value you want to return has to be on a single line, or you have to use parentheses


#3

To execute a function I need functionName(); - ok, but I don’t see where I missed parentheses.
I don’t get an error message, but it’s not adding up any sums (7.5 per order + 6% tax). It still prints all the Orders and the last line is ‘[Function: get total]’

Here’s the code again:

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 = (orderCount) => {
return getSubTotal * 0.06;
};
const getTotal = () => {
return getSubTotal(orderCount) + getTax(orderCount);
};

console.log(getTotal);


#4

here:

console.log(getTotal);

without the parentheses for getTotal, the function won’t execute, it will give you the function itself (or a reference to the function)


#5

Oh! yes. Thank you!
Cecilia


#6

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