If elseif else and the isEven function


Please help, as code runs perfectly, but continue to get an error regardless. I have checked other posts, but cant tell what is wrong.

This is my error message, although the code works perfectly, but will not let me move on in the course?
"Oops, try again. Your function returns true for 3!",

var isEven = function(number) {
  if (isNaN(number)) {
      return "This is NOT a number!";
      } else if (number % 2 ===0) {
      return "Yes, Number is divisible by 2.";
      } else {
      return "No, number is NOT divisible by 2";


what you are given

var isEven = function(number) {
  // Your code goes here!
      return true; 
          return false;

now your instruction:

Add an else if branch to your existing if/else statement. If the number put into the function is not a number at all, instead of return true; or return false;

so isNaN(number) should be inside else if statement.but you did inside of if statement


Thanks! I originally did it the way they instructed and got the same error. Here I rewrote as you mentioned and still get the same error, even though the console prints the correct string based on my inputs:

var isEven = function(number) {
if (number % 2 ===0) {
return "Number is divisible by 2";
} else if (isNaN(number)) {
return "This is NOT a number";
} else {return "Number is NOT divisible by 2";}



Nevermind. I replaced the return stmts with true & false......it didn't like my strings.......Sorry and thanks again!


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