Why is this giving me a Oops, try again. Looks like your function returns false when number = 2. Check whether your code inside the if/else statement correctly returns true if the number it receives is even


#1

var hop = 16

var isEven = function(number) {
// Your code goes here!

if (hop % 2) {

return true;

} else {

return false;

}
};


#2

This does not make sense. You have to say WHAT it should equal to if hop was used with a modulo by 2.

if(hop%2===___){


#3

var hop = 4

var isEven = function(number) {
// Your code goes here!

if (hop % 2 === 2) {

return true;

} else {

return false;

}
};


#4

It is still giving me an error


#5

That's because that equals 0:

You understand what a modulo(%) does, right? What it does is that it looks at the remainder.

SInce hop = 4, that makes the if statement actually be:

if(4 % 2 === 2){

But the answer is 0, because there is no remainder when dividing 4 with 2.

Why:

2 * 2 = 4
NO REMAINDER IS SHOWN (No Extra Numbers)

So it would work if you do it equal to 0, like this:

if(hop % 2 === 0){


#6

It still gives me the same error :grin:

var hop = 4

var isEven = function(number) {
// Your code goes here!

if(hop % 2 === 0) {

return true;

} else {

return false;

}
};


#7

Instead of using "var hop = 4" try using "isEven(4)" below the isEven function. Also change "hop" from the if statement to "number".


#8

Thank You that helps a lot :)smile:


#9

You never summoned the function... just saying...

isEven(hop);

#10

var isEven = function(number) {

if (number % 2 === 0) {
return true;
}else {
return false;
}
};
isEven(0); this finally works