"Oops, try again. Your function returns false for 2!"


#1

Hi, I keep getting this error for my following code. Do you know what's wrong? The error message that 2%2 === 0 is wrong makes no sense to me.

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

};
isEven("sup")


#2

Hey there! Most of your function and if statement is correct. First of all, you don't need an else if statement! It is only asking you for if and else. Also when you call your function, it says "sup". But you forgot to close it by putting a ';'! so instead of isEven("sup") you need to put isEven("sup"); with a semicolon. Hope this helped!


#3

@xxrazersharpzxx There are two exercises that look pretty similar and the second on requires an else if. But you're right one should add a semicolon after the function call.

@sdickers The problem with your code is this line:

else if (isEven=isNaN){

What you should do here is to check if number is really a number which would be done by isNaN(number). But what you do here is reassigning the variable that holds your function with a new value. Which is in this case the isNaN function so now isEven is just an alias for isNaN. So when the test function runs isEven(2) it really runs isNaN(2) which is obviously false as 2 is a number.


#4

You all were right! So simple. For the error message, it seemed like something much more complicated was happening.


#5

Yeah I know, I just remembered right after i had posted.
Anyways, no problem!