Don’t Repeat Yourself (D.R.Y) example – Codeacademy

Here is a correct example:

var orangeCost = function(price) {
var price = price * 5;
console.log(price);
}
;
orangeCost(5);

Instructions:
We will make a variable called orangeCost (very important).
The function can be named as you like, I’ve named it “price”.
Then we define price as price * 5.

5 = five oranges.

We type console.log(price) so we can have the result which should be 5 oranges * 5 dollars. It should result as 25.

Then we call the function as this: orangeCost(5).
5 is the price, aka. 5 dollars. It should result 25.

If you get this error: “Oops, try again. It looks like you didn’t define orangeCost.”, it means that you haven’t called the variable for your function as “orangeCost” (the first thing you type).

If you have any questions, leave in the comments.
This test was really hard for javascript novices.

dry-codeacademy

ONE COMMENT

  • Paul says:05.03.2017

    you’re repeating yourself buddy by defining the parameter as a variable.
    all u have to do is:

    var orangeCost = function(price) {
    console.log(price * 5);
    };

    orangeCost(8);

ADD A COMMENT: