If / else if / else


#1


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


It just keeps saying "Your function returns true for 3" does anybody know what is wrong?


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


#2

I think the problem lies in the fact that you make a string from true and false. Try to type true and false without the ""

This is my code and it worked:

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

};


#3

i am so stupid thanks!


#4

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