2. If / else if / else isNaN help pls


So if I put a number into the function it lets me move on. But when I want to try putting for example the letter j into the function it says j is undefined and gives me an error. So even though it lets me move on if I put a number, it means my code isn't working for when isNaN(number)

var isEven = function(number) {
    if(number % 2 === 0) {
        return true;
    else if(isNaN(number)) {
        return "Not a number, fool!"
        return false;


if you want to supply a letter as argument, the letter should a string:


otherwise, j would be a undefined variable


Ok thank you, didn't think to use the quotation. I was curious because I thought anything other than a number would trigger the "else if". I thought the isNaN would trigger with anything other than a number.


if you first define j:

j = "j"

then it will work. The point is that js will throw an error for an undefined variable.

If i ask you calculate x, you can't do that since you don't have the information needed to calculate x, same in js with undefined variables


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