2. Your function returns true for 3!


#1


More on Control Flow in JS lesson 2. If / else if / else


Everytime I run the code I get the error message"your function returns true for 3!"

I've tried adding to the first if [&& number !== 3] and [|| number !==3] but I still get the same error messages...


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


#2

isNaN is a built in function, here is some documentation about it, see how to use it, you use it slightly wrong.


#3

Gotcha! Thanks for the link.

It should be
--
else if (isNaN(number))
--
because isNaN() is a function!

Thanks


#4

yes, exactly, well done :slight_smile:

MDN has great documentation, i would highly recommend it if you ever need anything, you can just search: MDN isnan, or whatever you need on google.

Documentation is great to gain a more in depth understanding


#5

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