2. If/else if/else


#1

I need some help, even if my code shows every return I want, this error still occurs:

"Oops, try again.
Your function returns true for 3!"

var isEven = function(number) {
  // Your code goes here!
    if(number % 2 === 0){
          return "A variável é um número divísivel por 2";
    } else if (isNaN(number)){
        return "A variável é uma string";
    } else {
        return "A variável é um número não divisível por 2 nem uma string.";
    }
};

isEven(2);

#2

@designslayer72546,
Could you provide the link to the exercise.....


#3

Here's the link:

https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/2?curriculum_id=506324b3a7dffd00020bf661#


#4

@designslayer72546
Try it with

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

#5

Funny thing, it worked.

Can you explain me why? I'm a bit confused, mostly because the exercise tell us to return a string in all of them.


#6

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