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


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?


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


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.


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


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.


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