6.Don't Repeat Yourself (D.R.Y) - I don´t know what is wrong with my program x-x Help! - Already Fixed


#1

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(prompt("How much is the price for 1 orange this week?"))

//=====The answer comes out as 25 if I input 5 oranges, but it says that the answer doesn´t come out to 25...


#2

You Don't Need Brackets at price just do simple +price


#3

@guibar
First of all there is no space between the function and the parameter put inside parentheses. Second of all you don't need to put parentheses in around the price here:


#5

I left the parentheses because I tried to do

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

but it still didn´t work, so I just forgot about them ;/

and what do you mean by no spacing between the function and the parameter?


#6

Hi try to add return price inside your function.
The lesson want that you print 25 so if add a text to it, it won't work.


#7

So I tried to do return price as you said, but I still get the same error:
"Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5."


#8

Add it before the prompt and console.log.like tgat

price =price*5;
return  price 
confirm("The total price of the oranges is : "+(price));
console.log("The total price of the oranges is : "+(price));
}

#9

Thanks that worked!!


#10

The only thing is that the confirm, and the console.log don´t show up anymore ;/


#11

The lesson want you to only print 25 so when you add pompt and the other console.log() it's see it like a error


#12

Ohh I see thanks for the help!


#13

var orangecost = function (price){
price = price*5;
return price
confirm("The total price of orange is: "+ (price));
console.log("The total price of orange is: "+ (price));
};
orangecost(prompt("How much is the price for 1 orange this week?"))

this is the code i have made but it showing error saying Oops, try again. It looks like you didn't define orangeCost.
anyone can help me to come out of this error


#14

Hi you function should be

orangeCost

Instead of

orangecost

#15

thanks! this really helped a lot! I was really stuck on that one!


#16

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

The most easiest way!


#18

watch your language please


#19

haha, yes! That's what I did too.


#20

Well I'm doing almost the same, but console is printing the value 2 times.

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

costoNaranjas(5);


#21

farkhodkuchkarov you aregenius


#22

I found my problem. Using console.log replicates the answer. Use return insted. So you have to return the result of the orange price * 5.