I'm stuck and I don't know why it's not working (javascript functions)


#1



This isn't working and I don't know why...
I'm stuck at Javascript > Functions > 6. D.R.Y. Don't Repeat Yourself >> https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661

It's saying: "Oops, try again. It looks like you didn't define orangeCost."

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

orangeCost(5);


#2

You have defined the orangeCost function, but during the first execution you change value of orangeCost to 25 (5 * 5). So orangeCost is no longer a function and codecademy fails to test your submission.

Solution? Do not use the same name for many variables:

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

orangeCost(5);

:slight_smile:


#3

Thank you, that makes sense. My brain is getting scrambled over here. :slight_smile: Thanks again.


#4

You're very welcome :slight_smile:


#5

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