1/ If/else - Please help!


#1



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


#2

I keep on getting SyntaxError : Unexpected Token Else


#3

you're missing a ending } for the else, and you need to get rid of the semicolon after the if( )

so it should look like this...

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

#4

As @Ian Arsenault said you are missing }

Also

This semi colon after if condition needs to go


#5

yes what is the problem I wrote it like this and its wrong :expressionless:


#6

@mosabsaad best to create a new topic with your code, error message, and what you are having trouble understanding :slight_smile:


#7

Hi;) Do You still need a help with it?


#9

Thanks but I wrote like what you all suggested and it's still coming up wrong.


#10

Hi can you post your code?


#11

Ok - I finally got it. This is the correct code :slight_smile:

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

isEven was replaced with number because isEven is a function and cannot be compared to a number since it has no numerical value. We don't want to check if a function is divisible by 2, we want to check if number is divisible by 2.

Hope that helps.


#12