Introduction to function in js orangeCost


#1

this is my code. it says "SyntaxError: missing ) after formal parameters"
heres the code:

var orangeCost = function( Price * 5 ){
console.log("The cost of your oranges this week is " + orangeCost + " dollars.")
}
orangeCost(20)


#3

Now my code is different, and it says SyntaxError: missing ) after formal parameters.
here is my code:
var orangeCost = function ( Price * 5 ){
console.log("The price of your oranges this week is " + "" + Price )
}
orangeCost(5)


#4

You parse a parameter in a function, and while you do, you try to multiply the price by 5.

I would put price in as argument in the function, and the line below multiply it by 5:

var orangeCost = function ( Price ){
    /* multiply price by 5 here */
    console.log("The price of your oranges this week is " + "" + Price )
}

#5

what code do i put in the /* multiply price by 5 here */ part?


#6

Guys...
This is the code ...

var orangeCost = function(price) {
var cost = price * 5;
console.log(cost);
};
orangeCost(8); // you can change this number to get different result.

Hope this will help.. :smile:


#7

chipsurfer already spoiled the answer, i was going to let you think about that. I am not suppose to do all the thinking for you/provide full answers which you can just copy, i am here to help you.

You figured it out yet? and you understand why it is the way it is?


#8

OK, thank you for your kind help stetim94. But as you know i am beginner.
so here is the question.
how we should know to write var cost = price * 5;

because instructions on the course didnt tell us "you should declare a var "cost"". they just tell us declare a var called "orangeCost"

hope you understand me.

thank you


#9

Now, the instructions clearly state you need to multiply the parameter by 5:

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.


#10

thank you very much stetim94. we will discuss again :smile:


#11

var orangeCost = function(price)
{console.log(price * 5);
};
orangeCost(6);

This is how it should look like :smile:


#12

Answers with explanations help a lot. Just guessing stuff makes my brain explode. Thanks to chipsurger90065 for the explanation.

To others (below) how did you learn about "return"?


#13

programming is logical, not guessing. you can read about return here, that might help