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


#1


Hello, I am a little confused, not sure what I am missing.


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


#2

What makes you say that something is missing, what is the problem? What are you trying to change?


#3

ha sorry I meant to post more. Anyways the cost of the orange is supposed to be $5 and supposed to find the value of 5 oranges. However, it shows that it is calculating right $25 for 5 oranges, but a message pops up and says "Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5."


#4

You do print something, but that's not what is asked for


#5

var orangeCost = function(price) {
   price = 5; // problem is here
   console.log("Cost of oranges" + " "  + "$" + price * 5 );
};
orangeCost(5);

Change argument to 10. So, result should be 50. But you have 25 instead. It's because inside the function you assigned parameter price to 5: price = 5;

So, it doesn't metter what you put in price when calling the function. I think, you need to change parameter for function:

var orangeCost = function(quantity) {
   var price = 5;
   console.log("Cost of oranges" + " "  + "$" + price * quantity );
};
orangeCost(5);

Now argument 5 is a quantity of oranges and price is hidden inside the function.


#6

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