1/9 "Oops try again" even though code works


#1

here's my code:

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

isEven(4);

it returns true if the value is even, false if not. I'm getting this error message:

"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."

it's supposed to return false if the number is odd, no?

I'm so confused, what am I missing?!


#2

Yes but the point is you don't return true and false but "true" and "false". The first are booleans and the second are strings. Now the problem is that non-empty strings used in conditions behave like true so both "true" and "false" will behave truthy when a hypothetical test function asks for e.g.

if(!isEven(3))...

#3

ah, of course! booleans! thanks for your help