If/ Else if/ Else


var isEven = function(number) {
if(number % 2 === 0) {
return true;
else if ( number = isNaN) {
return "isNaN"
else {
return false;

When i run it says that my function is true for 3.

If/Else if /Else

Your second condition is not checking if number is === to isnan, it's assigning it to isnan.

That is why it skips to else.

If you're having trouble with writing your javascript read this topic to strengthen your code.


Correct but it should not check it either :smile:
It should rather call it:
isNaN(input) is true for if input is not a number and false if it is a number.


Help! I can't figure this out! Can you tell me what is wrong with my code? Thanks a lot!
var isEven = function(number) {
if (number % 2 === 0) {
return ("true");
} else if (isNaN(number) === true) {
return ("Not a number!");
} else {
return ("false");


You were really close...

First, true and false are booleans, but your making them into strings. Second, return does not need brackets like console.log(), so be sure clear those out as well! See comments below for further clarification:

var isEven = function(number) {
    if (number % 2 === 0) {
        return true;   //Not a string and does not need a bracket!
    } else if (isNaN(number)) {  //Defaults to true, no need to specify
        return "Not a number!";  //Returns do not need brackets!
    } else {
        return false;   //Not a string and does not need a bracket!

Hope that helps!


Thanks! It works! It helped a ton!!!


var isEven = function(number) {
if (isNaN(number)) {
return "This not a number";
else if (number % 2 === 0) {
return "it is Even";
else {
return "it is odd";

also error


so if number is a string, isNan(number) = false --> else if (condition in bracket is false), woudln't the "Not a number!" not run? because the code under the else if will only run if the condition in the bracket is true?


Yes if and else if only run their cases if the condition is true.
@pingfeng You still use strings as output instead of booleans have a look at @ekfuhrmann 's post.


so this is what i got
var isEven = function(number) {
if (number % 2===0){
return true;
else if (isNaN(number)){
return "this is not a number";
else {
return false;
isEven(); //this is where i got stuck a bit as if i put letters in that space gives me an error msg!


yet the code works Ahh the double edged sword!


minus the dollar sign at the end but I'm unsure


What do you mean by this?


I'm unable to enter a string or letter character in the ()


Thats because isEven(); at the end is causing the loop to run, I think you can put a number in but strings wont work


Well if there is an NaN option it makes sense that this is testable, doesn't it?

@wtrinity It really looks good, have you tried refreshing the page?
PS: I tried the exercise with your copyable code and I can pass without error message even if I enter strings.


ah yeah so it does, brain blanked :wink:


thanks for replying so you are stating that if i refresh the page the code i have written will work when i enter a string in the isEven() function
i.e. isEven(hat) ? @haxor789 @benjnev


Well hat is a variable name so at least it has to be "hat" or did you assigned a value to hat?
Yes if you're code is correct and yours seems to be ok then refreshing might help because it resets the javaScript which might help when failed attempts created memory that prevents you from passing.


ok i did not "" the string in the isEven() function and did not declare hat nor assign it