Exercise 6 - Introduction to Functions in JS


#1


Hi,

I just worked on the below exercise and I seem to be stuck a bit.. I keep getting the system warning that my function does not print out the correct result even though I can see my code working when I run it. I can't go past the system warning for some reason though..any thoughts?

Exercise:
You want to declare a function that calculates the cost of buying 5 oranges.
You then want to calculate the cost of the 5 all together.
Write a function that does this called orangeCost().
It should take a parameter that is the cost of an orange, and multiply it by 5.
It should log the result of the multiplication to the console.
Call the function where oranges each cost 5 dollars.


Error message:
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 (price) {
    var cost = 5 * price;
    console.log ("The cost this week for 5 oranges is" + " " + cost);
};

orangeCost (5);


#2

you should return rather then console.log() and you should return only cost without additional string


#3

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