6/13 Oops, try again. There was a problem with your syntax


#1

var orangeCost() = function(price) {
var val = 5*price;
console.log("val");
}
orangeCost(5);
THIS CODE IS WRONG!!! PLEASE HELP!


#2

val is a variable, you made the program display a string 'val' not the value of the variable.

Remove the double quotes from console.log("val");


#3

Thanks. I revised the code to look like this:
var orangeCost = function(price) {
var val = 25
console.log(val);
}
orangeCost(5);
When I click save, however, this time I get this back:
"Oops, try again. Make sure your function takes a parameter that is the cost of an orange, and multiply it by 5."
What do I do now?


#4

val = val * 5
replace var val = 25 with the code above.


#5

Change var val = 25 to var val = 5 * price. Everything else was fine it was just console.log("val") that was wrong before as far as I could see.


#6

That will give him an error since var val has no value.


#7

My code:

var orangeCost = function(price){
totCost= 5*price;
console.log("Total price is " + totCost);
}
orangeCost(5);

Problem: I'm getting two outputs:
Total price is 25
Total price is 25

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

Pls HELP.


#8

Hello! This is correct code, for example:

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


Main problem, that you didt finish 2nd } with ;
Have fun with coding!


#9

Thank you. You helped me to correct my code!


#10

This is what I put and it is correct

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

orangeCost (5);


#11

Thank s for your script code


#12

I put this in and it said it was valid. I did not add the additional variable that everyone else added...did I fubar?

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


#13

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

orangeCost(5);

easiest way to keep your variable just price


#14

I am closing this thread. The original poster's (@stu170255) problem had been resolved one month ago and other users are now bumping the thread with their own problems. Please post your problems in a new topic in the appropriate category instead of posting in old, resolved topics. Thanks! :smile:


#15