Issues with isNaN(number)


#1


https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/2?curriculum_id=506324b3a7dffd00020bf661


When I run this code, it always logs "Not a number" regardless of whether or not the argument is a number or not.
If the argument is a number, it will still log "Not a number" and then either true or false.
If the argument isn't a number, it logs "Not a number" twice.
Anyone know what's wrong with this and how to fix it?


var isEven = function(number) {
    if (number % 2 === 0) {
        return true;
    } 
    else if (isNaN(number) === true) {
        console.log("Not a number");
    } 
    else {
        return false;
    }
};
isEven(4)


#2

The thing to get away from very early on is comparing a boolean to a boolean. It is a moot comparison.

if (true === true)

is akin to

if (true)

#3

Try using return instead of console.log since it is what they wanted in the instructions.


#5

Replaced console.log with return and it's working now.
Thank you!


#6

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