# Lesson no.2, need complete code

#1

It says, "Oops, try again.Your function returns true for 3!"

``````var isEven = function(number) {
if(isNaN(number) === false) {
if (number%2 === 0) {
return true;
} else {
return false;
}
return "It's a number";
}
else if (isNaN(number) === true) {
return "It's not a number";
} else {
return "Fail!";
}
};

isEven(3);``````

#2

@nsanjay,
The isNAN() method will return a =true= or =false=
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN

I would also suggest to do isNaN() test
BEFORE you do an arithmetic-operations.....

#3

Hi I still cant get my code to work, please post your completed code, thanks!

#4

``````var isEven = function(number) {
if (number%2 === 0) {
return true;
// The following code will NEVER be excuted,
// as the previous =return= statement
// will EXIT the isEven() function
if(isNaN(number) === false) {
return "It's a number";
}
else if (isNaN(number) === true) {
return "It's not a number";
} else {
return "Fail!";
}
} else {
return false;
}
};``````

#6

I actually have the same problem...the "Oops, try again.Your function returns true for 3!" shows:

var isEven = function(number) {
if(isNaN(number) === false) {
return "It's a number";
}
else if (isNaN(number) === true) {
return "It's not a number";
} else {
return false;
}
};

isEven("patch");

Any suggestions on what I am doing wrong, or is it the editor?

#7

Same error, my code doesn't have the number 3 anywhere, yet I get this error and can't proceed.

var isEven = function(number) {
if (number % 2 === 0) {
return "it's true";
}
else if (isNaN (number) ) {
return "true"
}
else {
return "this isn't a number";
}
};
isEven("meow");