How do you write this?


this is my function but i keep getting an error that says "
Oops, try again. It looks like you didn't call the orangeCost function. Make sure to call it and pass it a price!"

var orange=function(price)
console.log("cost to buy an orange today " + price);
cost= price *5
console.log ("orangeCost " + cost);


What name do they say that your function should have?


i dont think they specified. the instructions they gave me were
"You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

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."


They specified it in what you wrote in your first post

And in your second


so i should change the name of my function to "orangeCost"?


Personally I'd go for strawberries but that's up to you man


what? no im saying is that what the name of my function is supposed to be? as in is that what was specified?


What I mean is, it says right there, you don't need to ask me!


first of all i was asking the general public not you, and when i did change the name i still got an error "Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5."


As part of the general public I took it upon me to reply! The instructions and error message said clearly what the name should be. You missed it the first time, we humans do that. Once aware it said there though, then you know as much as anyone, so it's yourself that you should rely on there.

Wouldn't you say this new error message is an improvement? Before it wasn't even finding the function, now it's complaining about how it behaves.


yes it is an improvement but not a big one because i still don't know what the problem is.


It tells you what argument it gave your function. It tells you what it expects. What can you do with that?

It also tells you your function didn't behave as expected.


i should fix it but i dont know what i did wrong because it does return 25 but the error says it doesn't


Maybe you're not returning 25. Maybe you're doing something else.
How does one return a value from a function?


i don't know, i don't think i've gotten that far


Here's some code similar to what the submission test does:

result = orangeCost(5);
console.log("orangeCost(5) returned: " + result);
console.log("is that equal to 25 ? " + result === 25);

What will that say that your function returns?


wouldn't it return 25 because your result is equal to 25.


If you're saying that I'm assigning 25 to result then no, I'm not doing that.
I'm assigning the result of calling your function to result, and then I never change it.


so i should assign a result for my function?


Nono. Your function should accept an argument, and return a result. No assigning required.

I should then be able to call your function, and make use of that result.

like so:

console.log("The price of 5 oranges is: " + orangeCost(5));

or even:

console.log("The price of 8 oranges is: " + orangeCost(5) + orangeCost(3));

console.log("Is there a quantity discount when " +
            "buying a hundred oranges?" +
            100 * orangeCost(1) > orangeCost(100));