Struggling with 6 (Don't Repeat Yourself)


#1

My code is

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

confirm("The total price of the oranges is : "+(price));

console.log("The total price of the oranges is : "+(price));

}
orangeCost(5)

It says my orangeCost() function doesn't return 25 when the cost of an orange is 5, and I have no clue what is wrong with it. Please help!


#2

Your code as multiple mistakes:

var orangeCost = function(price)
{
 price = price*5; /* there should parentheses around "price*5" */
confirm("The total price of the oranges is : "+(price)); /* this line is not necessary to pass this lesson, but if you want it here, delete the parentheses around your var "price" */

console.log("The total price of the oranges is : "+(price)); /* no parentheses around your var here */

}
orangeCost(5) /* add a semicolon here */

Hope that helped!


#3

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


#4

sorry...made a mistake...

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


#5

Hi and you should add a return statement inside the function

return  price

#6

Thank you very much! I've been struggling with this and it really helped!


#7

Glad to help! :slightly_smiling: