Help for number 2


#1

var isEven = function(number) {
    if (number % 2 === 0)
    {
        return true;
    }
    else if (isNan(number))
        return false;
    }
    else
    {
        return false;
    }
  
};

isEven("unicorns");

I don't get what is wrong with the code above.
It seems that there is an unexpected token "else".
Thanks for all your help


#2

That's as good a clue as any. Take a look at your code, specifically paying attention to lines involving your else ifs and elses. Check spelling, grammar and syntax.


#3

A slight mistype, perhaps. No doubt, you meant to write, isNaN(number)?

Supplemental

NaN is a peculiar object.

 > isNaN(NaN)
=> true
 > typeof NaN
=> 'number'

That is why the isNaN() method was created, to remove all ambiguity.

Don't worry about using NaN in your code. We never use it. Like undefined it is something that JS handles internally.


#4

yes, I completely missed that

Thank You


#5

Also I think that I forgot a "{" after the "(isNan(number))"


#6

Good catch! I knew you would find it. Now you know why we preach about braces having their own line (at least closing braces, anyway).


#7

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