Why is this isNaN not working?


#1

var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0)
{
return true;
}
else
{
return false;
}
else if (isNaN(number))
{
console.log("This is not a number!");
}
};


#2

you should put the else statement after the else if


#3

Thanks! Now it's correct!


#4

you can help me?
my code is not work.

var isEven = function(number) {
// Seu código vai aqui!
if ( number % 2 === 0){
return "true";
}
else if (isNaN(number)){
return "Informe um numero";
}
else{
return "false";
}
};
isEven("samuel");


#5

Hi try to remove the " " around true and false


#6

:weary:
wizmarco,

Thank you for help.

My code works now !


#7

My code is
var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0) {
return true;
}
else if ( isNaN(number); ) {
return "Sorry, your number is not a number";
}
else{
return false;
}
};
isEven(8);


#8

Hi this part you should remove the ;

else if ( isNaN(number); )  <== this one

#9

var isEven = function(number) {
// Your code goes here!
if(number%2===0)
{
return true;
}
else if(isNaN(number)=true){
return "the number is not a number!";

  }
  else{
      return false;
  }

}
};
what is the prob


#10

Hi this part you dont need to put isNaN(number) equal to true so remove =true.
And you should remove one } at the end you have more than you need


#11

Thanks! Now it's working! :wink:


#12

in the following code NaN is not recognized as a number but it is expected to advance this lesson. what am i doing wrong here ?

       var isEven = function(number) {
          // Your code goes here!
            if (number%2 ===0){
                return true;
            }
            else if (isNaN(number)){
                console.log(number+" is not a number");
            }
            else {
                return false;
            }
        };
        isEven(NaN)

#13

Hi you should call the function isEven() with a number.


#14

no, that's not the problem

if i run the function like this isEven(12) i get the same output:

NaN is not a number
true


#15

and you should change your console.log() to a return statement inside the else if statement


#16

ah thanks, that solved my problem


#17

don't use console.log. You mus use return (' words');


#18

var isEven = function(number) {
// Your code goes here!
var numCheck = isNaN(number);
var residue = number%2;

if (numCheck===true) {
console.log("You put not a number");
return false;
}
else if (residue===0) {
return true;
}
else {
return false;
}
}
isEven(4);

Please, look at my code. At first I check is "number" is a number. After my code should return true or false, depending on the residue. But it doesn't work... :frowning:


#19

Hi inside the if statement you should only return a string don't need to print it iwth console.log()

Edit:
I just see that it can work also like that

if (numCheck===true)

Because when the isNaN() is evalue to true the if consdition look like that

if (true === true)