1 If/Else


#1

Hi, I get the error isEven is not defined with my code:
var isEven = function(number) {
// Your code goes here!
if(number % 2 = 0) {
return"true"
};
else {
return"false"
};
};
console.log(isEven(4));
Can somebody please explain why? Thanks!


#2

Hi,

if(){
} else {
}

no semicolons after closing curly brackets

AND

number % 2 = 0

is no comparsion

number % 2 == 0

is a comparsion


#3

OHHH, I see. Thanks!
However, after fixing some bugs, I managed to get something out but now they said this, "Oops, try again. Looks like your function returns false when number = 3. Check whether your code inside the if/else statement correctly returns true if the number it receives is odd."
For this code,
var isEven = function(number) {
// Your code goes here!
if(number % 2 === 0) {
return"true"
}
else {
return"false"
}
}
console.log(isEven(3));
console.log(isEven(4));

Can somebody please explain why? Thanks!


#4

Where in the instructions did you read that you schould return a string?

Instructions
Write an if / else statement inside the isEven function. It should return true; if the number it receives is evenly divisible by 2. Otherwise (else), it should return false;.

Make sure to return - don't use console.log()!

Remove the quotes around true and false :smile:


#5

Oh woops. THANK YOU SO MUCH! I feel really dumb now, lol.