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


#1

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;
    console.log(val);
};

So obviously I'm a noob and this task completely lost me....

Thanks in advance :slight_smile:


#2

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; 
    console.log(total);
};
orangeCost(15);  would work out 15 * 5

Another way would be

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

which would return 60

Hope this helped :slight_smile:


#3

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:


#4

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:


#5

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