The other answers are correct at the time I type this but to explain
var isEven = function(number) {
// Your code goes here!
if(4 % 2) {
return true;
} else {
return false;
}
};
%
this is the modulus division operator. So it returns a value. Modulus tells you the remainder left over after division. So 4 modulus 2 returns 0 since there is nothing left over. Hence why you need to check against the returned value
var isEven = function(number) {
// Your code goes here!
if(4 % 2 == 0) {
return true;
} else {
return false;
}
};
If there is no remainder it is an even number because 2 divided it evenly with nothing left over. So 3 modulus 2 returns 1 since 2 divides three once and leaves 1 left over.
As per the comment below (seems it was deleted), it seems when talking in negative and positive numbers there is a difference between modulus and remainder but for strictly speaking javascript operator this is what it is defined as:
The remainder operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend, not the divisor. It uses a built-in modulo function to produce the result, which is the integer remainder of dividing var1 by var2 — for example — var1 modulo var2. There is a proposal to get an actual modulo operator in a future version of ECMAScript, the difference being that the modulo operator result would take the sign of the divisor, not the dividend.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
Also you have hard coded 4 into the if statement so it will always return true! The parameter of the function is number.
var isEven = function (number) {
// Your code goes here!
if (number % 2 == 0) {
return true;
}
else {
return false;
}
};