6. Don't Repeat Yourself


#1


I am looking for my error. I've tried a few different things. I am stuck at this point. If anyone can help, I would appreciate it. Thanks!

Exercise: 
You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

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.

Code:
var orangeCost = function (price){
    console.log("The orange cost is" + " " + price )
};
orangeCost(5) ;

Output: 
The orange cost is 5

Error:
Oops, try again. Make sure your function takes a parameter that is the cost of an orange, and multiply it by 5.


#2

So, one orange costs $5 and you want to calculate price of five oranges... Let me quote the error message:

Make sure your function takes a parameter that is the cost of an orange, and multiply it by 5.

And you should print to the console only the cost, nothing more :slight_smile:


#3

your cost isn't defined inside your function, so when you call your function you always get what you call and nothing more. Try to write: cost = price * 5 on the line before your console.log statement, switch price with cost inside your console.log-statement, and see what happens


#4

code:
var price = 5;
var cost = price * 5;
var orangeCost = function (price){
console.log("The orange cost is" + " " + cost)
};

orangeCost(cost) ;

error:
Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5.

output:
The orange cost is 25
The orange cost is 25


#5

the exercise is also going to call the function, you should the multiplying inside of the function


#7

I'm having the same problem. Monitoring this Q&A to see if anyone has answers.


#9

Thanks for the insight everyone!! =)


#10

Posting answers is not according to the guidelines, if you need help make a new topic with your code so someone can help you, and you actually understand why your code was not working