Don't repeat yourself. Printing the log twice


#1

Hello, I have just started the javascript course and everything was working great until I reached "D.R.Y.".
I have the code below:

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

and the output is:

The oranges cost 25
The oranges cost 25

(No mistyping there, it prints it twice.)

The final price is $25, however I get this error message:

"Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5."

Any kind of help would be greatly appreciated. Thank you in advance.


#2

The problem is that your solution is too good. The exercise only expects to see a number so here 25 but you give some explanation as well. This is good and you should be keeping this but to pass the exercise you need to get rid of the additional string.


#3

stupid question, why does the string get printed twice with:

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

and once with:

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

i only removed "The oranges cost " + from the second example


#4

That's not a stupid question, I guess it that comes from the test cases that are run on the function. Maybe it gives it a second try if there was a problem with the code.