1. If/else


#1


https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/1?curriculum_id=506324b3a7dffd00020bf661#


This code keeps on giving me false if the number is the same as the divisor

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

Don't know what I've done wrong


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


#2

In the condition after the if you're not using proper condition syntax. Instead of "number % 2" write "number % 2===0".


#3

ok it works but why exactly should i do that? i still don't get the differences between the equal signs


#4

Because when you're writing "number%2" you're not checking whether the number is even. When you're writing "number%2===0" you are. The modulus function focuses on the remainder, and an even number divided by two always returns a zero. Hence why it's true.

Also when you use "===" you're comparing and when you use "=" you're declaring.


#5

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