Error in Functions! - Pizza getTotal


#1

Howdy,

I’m having trouble getting my getTotal function to return a value. Can anyone see what’s going on here? :pray:

https://www.codecademy.com/courses/learn-javascript-functions/lessons/functions/exercises/return-ii?action=lesson_resume&program_content_id=7ab3b34edca64ceb6005f8e1e4410d30&program_id=fc1cc76cbdee0831fda0677e3fd75ae6

MY CODE

let orderCount = 0;

const takeOrder = (topping, crustType) => {
itemCount= 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= () => {
return getSubTotal * 0.06;
};

const getTotal= () => {
return getSubTotal + getTax;
};
/* It’s got to be some thing around this function*/

console.log(getTotal)

RESULT

Order: thin crust pizza topped with mushroom
Order: whole wheat pizza topped with spinach
Order: brooklyn style pizza topped with pepperoni
22.5
[Function: getTotal]

^^^^ wtf?


#2

Hi @jamesmacleod1990,

You need to make a function call with ( ) brackets and insert an argument, which is orderCount in it, like:

getSubTotal(orderCount) * ....

Same here, make two function calls with ( ) brackets, one for getSubTotal with an argument orderCount, the other one for getTax.

Finally, you still need to invoke/call the getTotal function with one pair of ( ) brackets. console.log(getTotal())

Change that it should be working.

Hope it helps :slight_smile:


Note: Notice you’re a new user here. Welcome! :smile:

It would be a kind gesture if you can go through the post here (Learn more) to edit/format your code. It definitely helps a lot if you have any more questions to ask in future.

Because of how Discourse (this forum) works, your code without proper format get twisted when I copy paste into my own environment. I would need to edit the code first before going through it.

So, it is much appreciated if you could edit/format code in the right way. That said, sorry for the long post and Happy Coding! Cheers! :slight_smile:


#3

@codexthon Thank you!


#4

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