More on Control Flow in Javascript


#1

I'm wondering if anybody can give me a sample of code and some advice on mine?

var isEven = function(number); {
** if (number % 2 === 0); {**
** return true**
** };**
** else if (isNaN(NaN)) {**
** return "This is not a number.";**
** };**
** else {**
** return false**
** };**
};


#2

First, format your code.

Then:

You have an unneeded semicolon.

You should check number instead of NaN.

You need ending semicolons.


#4

Okay, this is my edited version, using your advice.

var isEven = function(number); {
if (number % 2 === 0) {
return true;
};
else if (isNaN(number)); {
return "This is not a number.";
};
else {
return false;
};
};


#5

A couple more things.

Remove marked semicolons, as they end your logic. (After else is optional)

Here you have an unneeded semicolon.