Introduction to function in js orangeCost


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


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 )


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 )


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


This is the code ...

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

Hope this will help.. :smile:


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?


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


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.


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


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

This is how it should look like :smile:


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


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