If / esle if/ if BUG


#1

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

My function is called once and should only run once, it didn't work like it should so I asked a more experienced programmer for help and we did some testing in my program. It turned out that my function was called about +1000 times but for no reason to be found in my program.


isEven =function (number) {
  // Your code goes here!
  //I used the console.log to test what's wrong 
  console.log("l");
  if (number%2===0) {
        return true;
  }
  else if (isNaN(number)) {
        console.log("trala");
  }
  else {
        return false;
  }
  
  return false;
};

isEven(3);


#2

you log a string to console when number is not a number, it should return the string instead

Yea, the exercise needs to validate your function works correctly, how do you think this is achieved? Indeed, by calling the function


#3

I get this problem in my output


#4

when the function input isn't a number, return a string. You log a string to the console when function input is not a number

logging != returning

I already covered this in my first answer?


#5

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