D.r.y


#1

var orangeCost = function(price)
{
console.log("orange cost " + " " + price * 5)
}
orangeCost("5")

I'm so confused-


#2

Hi @purplefurleafclan

When you call your "orangeCost" function, you have to put a number :

orangeCost(5);

Hold on :wink:


#3

Well try this:

var orangeCost = function(price)
{
 console.log("orange cost " + " " + price * 5) // Add Semi-Colon to the end of this line
} // Add a Semi-Colon to the end of this line.
orangeCost("5") // Take out "Quotation marks", and Add a Semi-Colon to the end of line

#4

In addition to what was already written the exercise expects to see a number so instead of "orange cost " + " " + price * 5 better write just price * 5. In genereal it is a really good idea to make the output as user friendly as possible but as said some exercises are rather strict about what they expect to see.


#5

var orangeCost = function(price) // price function
{
console.log(price * 5 ) //calling function + * 5 because is $5 dollars each orange
}
orangeCost("5") //calling var + number = job complete =)

:grinning:

List item


#6

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

this is how the solutin looks like, but i think your issue was the fact that you added the price of one orange cost to the the price of the one orange cost that should be multiplied by 5. anyway, if you take out "orangeCost" your code should work. :wink:


#7

Why does it say that this:

var orangeCost = function (price) {
var val = price * 5;
console.log("The price of 5 oranges is" + " $" + (val))
}
console.log(orangeCost (5))

is wrong?


#8

Because you're using a "console.log" statement on another "console.log" statement. make the console.log statement inside of the function instead look like this:

var orangeCost = function (price) {
 var val = price * 5;
 return "The price of 5 oranges is $" + val;
}

#9

What about this one right here:

var orangeCost = function(price)
{
var total = price*5;
console.log ("The total will be"+" "+total);
};
orangeCost(5);

Why the output of that is:

The total will be 25
The total will be 25

Looks like changing console.log to return solves the issue (duplicated result), but I would like to understand why.

Thanks in advance :smile:


#10

Honestly that's a new one for me. I'm not sure why it duplicates the result but I'm glad my answer was able to fix the error for you.


#11

:stuck_out_tongue_winking_eye: