Calculating


#1

I cant seem to calculate with my code using JS. What am i doing wrong?
var orangeCost = function(price * 5)
That's my code, but i doesn't work. Could you please help me?
It says "Unexpected token *"


#2

Hi @coding_is_awesome

Your code should be looks like

var orangeCost = function(price){
    return price * 5;
};

orangeCost(3);

Do you understand those changements ?


#3

What does the return part do?


#4

He stops the execution of the function and returns a value from that function.

It's all what I know about return statement. And you @lolman ?


#5

But do you know why it says that * is not correct in this code? (my previous)
Just for knowing in the future.


#6

No I can't know, I think it depends of your code :confused:


#7

I cant use > or < either, it says the same


#8

Show me it I'm going to check


#9

I think i get it: if you do 'var orangeCost = function()' you cant put any calculative stuff between the ()


#10

Why is there a (3) behind orangeCost?


#11

var orangeCost = function(price){  //no calculative stuff between (), here is function's parameters, just put value who will call
    return price * 5;              //here you put calculative stuff or other, price will be replace to the value who will put
};

orangeCost(3);                     //now, you call the function and put a parameter, orangeCost's going to do 3 * 5 and return result