Don't repeat yourself D.R.Y Help


I don't understand what I'm supposed to be substituting in this function. Nothing gets me the right answer.

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


Hi tanayag

  1. Instead of returning price it should be orangeCost because that's the variable.
    price is just a place holder so you know what to put in there

2.also in console.log if you want it to display the awnswer just type in orangeCost in console.log not price 5


The assignment asks for a function that takes the parameter, multiplies it by 5 and then logs it to the console. On line 2, you assign your parameter 'price' a value of cost * 5. Cost is undefined. If you call your function, the result will be undefined.


assignment should introduce return syntax...
When I saw it here I tried but it seems it can not execute to console

var orangeCost = function (price)
return (price *5);
console.log("Orange" + price);




In your return statement, you don't need the parentheses. Your console.log won't run after a return statement.

I would remove the quotation marks. Those are meant to denote text strings.


var orangeCost = function (price)
return price *5;
console.log("Five Oranges" + price);



Tnx @biff75
I just wonder why it doesnt print "Five Oranges" in console, just price.


var orangeCost = function(price)
console.log("price of oranges" + " " +5*price);

By executing above code, i got output like "price of oranges 25" .But after clicking on the save and submit button it gives an error like "Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5."


It looks like console cannot be reached after return.
Whatever I try its not printing.


Try placing your console.log statement on the line above your return statement in the orangeCost function.


Try using a return statement instead of console.log statement in your function.



This explains it all :slight_smile:

The return keyword simply gives the programmer back the value that comes out of the function. So the function runs, and when the return keyword is used, the function will immediately stop running and return the value.


it works with
var orangeCost = function(price)
var cost = price*5;

Thank you!


cost looks undefined here----


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