Stuck at "More on Control Flow in JS" 2/14


#1

I have no idea what's wrong with my code. Please, help. Thx in advance!

 var isEven = function(number) {
     if (isNaN(isEven)) {
         return "The number you wrote isn't a number."
         } else if (isEven % 2) {
         return "true"
         } else {
         return "false"
         };
 };

#2

Two things, first of all you need to use true and false instead of "true" and "false". Because in javaScript every value acts as a boolean when used in a condition and non empty strings are treated like true so both "true" and "false" act truthy in this manner. Also think about this condition:

isEven % 2

Do you really want to test if the whole function is divisible by 2 without rest? Is a function divisible at all? Also What if you assume that isEven would be number instead and would be an even number? In this case it would be 0 and zero has also a boolean value of false. Might have heard about 1 being true and 0 being false.
A full list of this values to booleans can be found here:
http://www.sitepoint.com/javascript-truthy-falsy/


#3

I've read your answer the stuff on the link—quite informative. But I still don't get how to pass that exercise. My current closest guess is:

var isEven = function(number) {
if (number % 2) {
return true;
} else if (isNaN(number)) {
return "The number you wrote isn't a number.";
} else {
return false;
}
};


#4

pretty close but this does not check if it is even:

number % 2

let's assume number is 2 that 2%2 is 0 and 0 is a falsy value so this case is not choses although it is true. So either you need to use the not-operator here or you need to compare this to 0 in order to choose this case if the number is even.


#5

var isEven = function(number) {
if (number % 2 === 0) {
return true;
}
else if (isNaN(number)) {
return "your number is not a number";
}
else {
return false;
}
};

This should work Try It