6. Don't Repeat Yourself (D.R.Y)


Can someone help me out with this code?

I keep trying to declare the fruit variable and the cost variable but I’m just not getting it…
I know I’m doing something wrong but can one of you write a code for me that actually does what this section is asking so I can see where I’m going wrong?

var orangeCost = function (cost)
var orange = function (price)
    var val = orange * 5;

So obviously I’m a noob and this task completely lost me…

Thanks in advance :slight_smile:


There are a couple ways you can approach this the way for you would be this as you haven’t gotten to the return statement yet.

var orangeCost = function(cost) {
     var total = cost * 5; 
orangeCost(15);  would work out 15 * 5 

Another way would be

var orangeCost = function(cost) {
return cost * 5; 

which would return 60

Hope this helped :slight_smile:


Oh that’s Awesome! Thank you very much benjnev :slight_smile: The first one code it didn’t like for some reason. But I wrote you the second method and it worked like a charm!
Thanks a lot again :wink:


this is why the first one wouldnt work, if you copied this whole line in mean’t to put "would work out 15 * 5 as a comment / on a new line. Remove this bit:

and that will work also :smiley:


Ohhh Snap! So it did! :blush: That’s brilliant, thanks a lot!