Stuck on this one, anyone know what i did wrong?


#1



It's on "Don't Repeat Yourself (D.R.Y)" and i have no idea what i'm supposed to do.
I get the error "Oops, try again. It looks like you didn't define orangeCost."


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


#2

Basic function syntax

var
identifier
=
function
(parameters)
{
// code
};

There should be a variable in the parameter, not a literal.

... = function (price) {
    console.log(price * 5);    // use whichever line is asked for; this
    return price * 5;          // or this
};

Note that there is no semicolon after the parameter.


#3

then i get this error: SyntaxError: Unexpected token *


#4

Please let us have another look at your revised code. Thanks.


#5

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


#6
var orangeCost = function(

Everything up to here is correct. The parameter may not be an expression unless it is a default assignment, such as price=5. In this case we want to define a local variable called price and use it to store the argument. That will give us this for a function definition:

var orangeCost = function (price) {

};

That line will not print to the display what we expect. unless we are looking for,

[Function]

What we want to do is multiply the value stored in price by 5 and log it.

console.log(price * 5);

Finally we call the function,

orangeCost(5);

The 5 is the argument and will be stored inside the function in price. The output to the display will be,

25

#7

I did it, thanks for the help!


#8

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