mercredi 11 novembre 2015

if statement not returning true

I am supposed to be getting a number that is divisible by two and I am doing that. I am not sure why my code is not working. I'm doing this in a course to learn javascript. There error I get is this:

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.

The question is this:

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()!

My code

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

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire