A bizarre result in "Don't Repeat Yourself (D. R. Y)"


#1



When I call the function that calculates the cost of oranges, the desired result gets printed to the console. Yet my code is not accepted, with the message saying, "Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5." Meanwhile, over at the console, it says "This week's orange expense is $25." What is wrong here? Below is the Famous Code that Returns but Does Not Return 25:

var orangeCost = function(cost) {
    var orangePrice = cost;
    var totalForOranges = orangePrice * 5;
    console.log("This week's orange expsense is $" + totalForOranges + ".");
};


For the life of me, I don't see anything wrong with the above code. Yet, obviously, something is. What is it?


#2

Embellishment is the issue. The output expected in the console is,

25

All of the above code is window dressing, and bloat, to be frank. In simple terms is should be a single statement that logs cost * 5.


#4

Thanks! When I modified my code to simply return the number, everything worked.


#5

It's how a lot of exercises work. Bare bones and simple. We can explore afterward, but in lessons if we stick to the instructions we get better results and the lessons go by quickly. Remember to review and experiment when you reach the end of a module.


#6

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