Don't Repeat Yourself (D.R.Y.) Calculating Oranges Question


#1

I am having trouble with Don’t Repeat Yourself (D.R.Y) Calculating Oranges. I have done this so far:

var price = prompt (“Price of a orange”);

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

My code doesn’t seem to be working correctly. I was wondering if someone could help clarify or explain this to me? Thanks in advance!
Here is the link:
https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661


#2

Hi @helenbella, let’s see what your code does right now:

We declare our variable, price that has a prompt: prompt("price of an orance"); assigned (=) to it. prompt will ask us to type something in.

Next, we have our function orangeCost, JS knows it’s a function because we assigned it to function(). In the body of the function (which is within the brackets), we use console.log() to print price multiplied by 5.


There is a problem, though. We can’t do math with a string and an int. :man_shrugging: You should reread the instructions, think about what they’re asking you to do, and try again. :slight_smile:


#4

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