Functions 5 Return. Why cost is 0?


#1

https://www.codecademy.com/en/courses/learn-javascript/lessons/functions/exercises/return

var orderCount = 0;
function getSubTotal (itemCount){
return itemCount*7.5;
};
function takeOrder (topping, crustType) {
console.log ('Order: ' +crustType +' pizza topped with ' + topping);
return orderCount=orderCount++;
}
takeOrder('bacon', 'thin crust');
takeOrder('tomat', 'jhf');
takeOrder('ytt', 'uytt');
console.log(getSubTotal(orderCount));

Why i get cost 0? And where I can find already made correct codes?


#2

First off, just a minor thing, remove the semi-colon at the end of your first function (you don't need it) :slight_smile:

Regarding your error, when you return something at the end of a function you are returning something like a value calculated in the function. You only need to do that in your getSubTotal() function because you're taking a value from it.

Go into your takeOrder() function, and change return orderCount=orderCount++ to orderCount++. You are simply adding to the orderCount variable, meaning you don't need to return anything.


#3

Thanx. Do you know where i can find the premade codes?


#4

Can you expand on 'premade'? Do you mean the original code provided?

And if my solution helped, feel free to mark it as a solution and feel free to like it :slight_smile:


#5

I mean, are there any done codes for the excersises, so I could compare them to what i made?


#6

There are no pre-written solutions to the exercises. I would provide my own solution, but I haven't done that course (I did the original JavaScript course).


#7

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