6/13 orangeCost not defined


var price = function(orangeCost) {
var val = price*5

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

1 Like

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

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

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.


var orangeCost = function(cost){
var orangeCost = cost*5;

that’s what I did
try it

1 Like

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

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


It works just fine.


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?

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.

1 Like