6/13 orangeCost not defined


#1

Code:

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

It keeps telling me orangeCost is not defined, does anyone know why?


6/13 Please Help
#2

Hi, at this line you should use a variable or a parameter (orangeCost)

at this line you should use name of the function (price).


#3
var price = function(orangeCost) {

Here you confused the name of the function with the name of your parameter. The exercise tells you that the function name is orangeCost so it should rather look like this:

var orangeCost = function(price) {

the rest seems to be ok.


#4

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

that's what I did
try it
https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661


#5

You actually don't need the variable declaration part; it can just be:

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

orangeCost(5)

It works just fine.


#8

That one worked! But what I don't get is that earlier it stated a semi colon should be at the end of every line in a function? There is none in yours though after // console.log(price * 5).

Any reason why its not necessary here?


#10

A semicolon ends a statement but in JS also a linebreak ends a statement and the semicolon is placed automatically by JS. The debates about the semicolons being necessary have gone to almost religious proportions... If you want to minify your code e.g.

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

you definetely need them otherwise they are rather optional. In other programming languages like Java or C++ they are mandatory.


#12