Not working! I'm confused


#1


My code returns true for 3, does anyone know why this is?


var isEven = function(number) {
    if(number % 2 === 0){
        return true
    }else if(isNaN("number") === true){
        return "This isn't a number"
    }else{
        return false
    }
  
};


#2

Are you sure about that?

console.log(isEven(3));

#3

"number" is a string with its ""-s so took it off. We are looking for the value of the number, not the word "number"

And run the function after all so you can try it. Put
isEven(8); or

isEven(7); or

isEven("seven");

or anything else to try the function you wrote.


#4

you should use return not console.log


#5

Nope, @ionatan proposed to add this console.log statement at the end of the script to test if it really returns true for 3. return would cause the illegal return statement error.


#6

else if(isNaN(number) === true){
then all the other stuff


#7

var isEven = function(number) {
if(number % 2 === 0){
return true
}else if(isNaN(number)){
return "This isn't a number"
}else{
return false
}

};
isEven("dfsf");


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.