JS Control Flow: If/Else (Error for getting a correct return?!)


#1

More on Control Flow > If/Else: https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/1?curriculum_id=506324b3a7dffd00020bf661#

I'm VERY confused! There's probably something up with my syntax (feel free to give me some pointers on that, as well), but now I'm not really sure what to do because the error message is yelling at me for getting a result that the instructions asked for!! The instructions for the activity say to write an if/else function that returns "true" if a number is divisible by 2 (even), or false if it is not divisible by 2 (odd). The error I just got says "Oops, try again. Looks like your function returns false when number = 3. Check whether your code inside the if/else statement correctly returns true if the number it receives is odd. So, is it some misunderstanding on my part, or is there something in the activity that's making this such a pain???? This is driving me so crazy!!

var test = 0

var isEven = function(number) {
  if (test % 2 === 0) {
     return true;
  } else {
      return false;
  };
};

Any help will be greatly appreciated!!!!

UPDATE: I did get my syntax straighten-out and passed the activity, but I'd still like to know what's up with this error! Did I read something wrong or is the error totally out of whack?


#2

Your if statement should be checking the function parameter number,

if (number % 2 === 0) {

and you don't need a global variable test,

var test = 0


#3

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