2. if/else if/else what is wrong I don't know


#1

var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0) {
return 'ghjhgj';
} else if (isNaN(number)) {
return "This is not a number!";
} else {
return false;
};
};

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

What I did wrong? :confused: :relaxed:


#2

Hi try tot make your if statement return true and your else if statement return false then for your else statement return "This is not a number!";


#3

@wizmarco Like as this?

var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0) {
return true;
} else if (isNaN(number)) {
return false;
} else {
return "This is not a number!";
}
};

Oops, try again. Make sure your if/else if/else statement returns a string when the function input isn't a number.


#4

Try it like that your else if statement return a string
And your else statement false


#5

Okay @wizmarco, I'll do same again.

var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0) {
return true;
} else if (isNaN(number)) {
return "This is not a number!";
} else {
return false;
}
};

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


#6

Strange I just try that code and it works

var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0) {
return true;
} else if (isNaN(number)) {
return "This is not a number!";
} else {
return false;
}
};

#7

Look at this picture. I hit save and submit. Strange maybe, but still true.


#8

Try to refresh the page or change the browser .


#9

That is strange for me. Code works fine now. Thanks! :relaxed: