Undefined error.... function concept


#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/en/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661#

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

Oops, try again. Hmm, it looks like your orangeCost() function doesn’t return 25 when the cost of an orange is 5.

```

var orangeCost = function(orange_price) {
var res = orange_price * 5;
console.log(“price value of single orange is” + " " + orange_price);

console.log(“total cost is” + " " + res);
}

console.log(orangeCost(5));

<do not remove the three backticks above>



here with correct output default answer is displaying that is each time with new price line 3-5 displaying same (from 3rd lineto 5th )
i.e output below 

price value of single orange is 10
total cost is 50
undefined
price value of single orange is 5
total cost is 25

#2

just log the total cost (res) to console without any further string, only then can you pass the exercise


#3

if i do like that i get below output
total cost is 25
undefined
total cost is 25

so i just returned to function & finally i got the output
the total cost of 5 orange is 50

code is

var orangeCost = function(orange_price) {
return orange_price * 5;
}  
console.log("the total cost of 5 orange is " + " " + orangeCost(10));

output is

the total cost of 5 orange is  50

#4

That seems to be working fine?


#5

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