Don't repeat yourself (D.R.Y) - Bug?


Okay, so here's the assignment:

  • You want to declare a function that calculates the cost of buying 5 oranges.
  • You then want to calculate the cost of the 5 all together.
  • Write a function that does this called orangeCost().
  • It should take a parameter that is the cost of an orange, and multiply it by 5.
  • It should log the result of the multiplication to the console.
  • Call the function where oranges each cost 5 dollars.

var orangeCost = function (price) {
    5 * 5;

Why does this code pass the test?


Poorly written test.

Regardless, I think it's important that you yourself verify that your code acts the way you intend for it to act, that you create some kind of "if I do X then i get result Y" as opposed to "if I do X then I pass" which isn't useful


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

^that code becomes this:

the oranges Cost function (price) {
return price * 5;}

why isn't the output "the oranges Cost 25"?