If/else error


#1

Hi my code keeps returning false if the number is 3. I'm not sure how to fix that...

var isEven = function(number) {
  // Your code goes here!
  return number;
  if(isEven % 2 === 0){
      return true;
  } else {
      return "this is not a valid number";
  }
  isEven(36);
  
  
};

#2

Hi,

This problem could appear because of a mismatch with the instructions to the task. Read carefully all instructions to the task and compare your code to comply with these.

You can try this first solution:

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

Or this second solution:

var isEven = function(number) {
// Your code goes here!
if (number % 2 == 0) {
return true;
} else if (isNaN(number)) {
return "This is not valid value!"
} else {
return false;
}
};


#3

I tried the first example and it worked! Guess I was confused about the instructions. Thank you so much!


#4

You're welcome! :slight_smile:


#5

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