Exercise #2 Issue: Your function returns true for 3!


#1


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

I think I might be missing something obvious in the question, but I'm using isNaN and my function is correctly flagging the string in the function.

This returns "This is not a number"

Is this not what the question is asking?

Getting: Oops, try again. Your function returns true for 3!


var isEven = function(number) {
  // Your code goes here!
  if (number % 2 === 0) {
      return true;
  } else if (isNaN(number)) {
      return number;
  } else {
      return "Not an even number.";
  } 
};

isEven("This is not a number");


#2

It wants your return to be false not true when 3 appears so change your else return statement to false and I believe that should fix your problem


#3

Thanks! The following now works:

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

isEven("3");

Unless my brain isn't working today the question itself is rather confusing. But this makes sense now. Thanks again!


#4

No problem! Glad to have helped! :smiley: Yeah it definitely can be due to how the instructions are worded but ultimately you just got to reason it out logically or ask for help on the forums which sometimes I perfer and need because I ain't always logical xD


#5

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