I need help with this if/else statement


#1

I'm having trouble understanding what is wrong with my if/else function. When I run it, it prints the wrong answer to the console.

When I run it, it says,"Oops, try again. Looks like your function returns false when number = 2. Check whether your code inside the if/else statement correctly returns true if the number it receives is even."

 var isEven = function(number) {
  // Your code goes here!
  if(number % 2) {
      return true;
  }
  else {
      return false;
  }
};
isEven(2);

#2

That will be 1 (boolean true) if the value is odd, so should return false.


#3

Thank you, that helped


#4

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