5.2 More on control flow in JS : A little bit stuck hehe :C!


#1

var isEven = function(number) { //you see this number? where will it go
if (number % 2 === 0)
//if the number you call your function with gives zero as a remainder when divided by two
{
return true;
} 
else if  (isNan("isEven"));
{
    return "Your input is not even a number";
}
else {
return false;
};

isEven(9);// you need to declare the function and give it a value!

#2

You're checking the string to see if it's a number or not, but you should be checking the parameter supplied in the function, and it's isNaN(), not isNan() :slight_smile:


#3

Thanks! but it still doesnt work haha

var isEven = function(number) { //you see this number? where will it go
if (number % 2 === 0)
//if the number you call your function with gives zero as a remainder when divided by two
{
return true;
} 
else if  (isNaN(number));
{
    return "Your input is not even a number";
}
else {
return false;
};

isEven(9);// you need to declare the function and give it a value!

#4

What's the error message?


#5

SyntaxError: Unexpected keyword 'else'

Oops, try again. There was a problem with your syntax.


#6

Sorry, I can't believe I missed that! Below is the code you posted, but I removed the comments, changed the layout a bit (to improve readability), and I commented where the errors are.

Note: I did not fix the code, I only told you how to. If you just copy the code as it is below, it won't work.

var isEven = function(number) {
    if (number % 2 === 0) {
        return true;
    }
    else if  (isNaN(number)); { //remove semicolon on this line
        return "Your input is not even a number";
    }
    else {
        return false;
    };
//Add a } on this line
isEven(9);

#7

Thank you so much!! Cant believe I missed that too :sweat_smile:
of course I dont need to put a ; after an if statement !!


#9