Code is functional; Edit : I passed!


#1

I am really stumped on this one, my code functions just as expected. Even numbers return true; odd numbers return false; and no input returns Not a Number!

"Write an if / else statement inside the isEven function. It should return true; if the number it receives is evenly divisible by 2. Otherwise (else), it should return false;.

Make sure to return - don't use console.log()!"

 var isEven = function(number) {
  if (number % 2 === 0)  {
      return "True";
  }
  else if (isNaN(number)) {
      return "Not a Number!";
  }
  else  {
      return "False";
  }
};
isEven(3);

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

Prob is the instructions and the Error conflict with one another; or there is something I am missing?


#2

lol I figured it out. I was returning the string "True" "False" and not a Boolean value true false.

I just removed the quotations around true and false; as well as made those values lowercase.

My working code is as follows.

 var isEven = function(number) {
  if (number % 2 === 0)  {
      return true;
  }
  else if (isNaN(number)) {
      return "Not a Number!";
  }
  else  {
      return false;
  }
};
isEven(3);

#3

The problem is that any value used in a condition is evaluated as either true or false and non-empty strings are treated as true so if you have

if(!isEven(3))

it goes isEven(3) --> "False" --> truthy -> true and negated !true -> false. So be careful and use booleans if booleans are needed.