Your function returns true for three


#1


My code says even with real numbers but odds return "your function returns true for three"
I cannot figure out whats wrong

var isEven = function(number) {
    if (number % 2 <= 0){
        return "even";
    }
    else if (isNaN(isEven) === true) {
        return("dis are not reel number");
        }
        else{
    return "odd";
    }
  
};
isEven(3);


#2

you should return boolean values, true for even numbers, and false for odd numbers. Not strings


#3

isNan is a function should followed by parameter which is "number" in this exercise.

another thing to add.

" isNaN(isEven) ===true "

is the same as "isNaN(isEven)" only to make is simple.

here is mine.

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

if(isNaN(number)){
return "that is not a number";
}

else if ( (number % 2) === 0 ){
return true;
}

else{
return false;
}

};

isEven("mama");


#4

I Changed my code and it works, but I still get a "return for three"

var isEven = function(number) {
if (number % 2 <= 0){
return "even";
}
else if (isNaN(number)) {
return("dis are not reel number");
}
else{
return "odd";
}

};
isEven(2);


#5

The question is asking you to return either true or false, try making your if / else return booleans (true or false), rather than the strings you are using. My code is under as a example.

var number = 0


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

Try this and if that was the problem please mark my answer as the solution. :slight_smile:


#6

@oscartbeamish is right, you are still returning strings ("even" and "odd") while you should return boolean values (true an false)


#7

I'm not sure where "return for three" come from, but look at the code above. if you want to get even value, the code should be " if(number%2 === 0)" that's mean if "the number / 2 and the remainder is 0 === 0" statement is true
then execute the code inside the curly bracket.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.