If/else question


#1


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


Hello, I'd like to know why this code isn't considered right, am I supposed to use else if at all?


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

isEven(123);


Thanks in advance!


#2

You want to check if the parameter (number) you put into your function is even. Not the function itself.


#3

Ohh
I guess this explains all, thanks!


#4

This is my code at the moment:

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

isEven(3);

but i am getting:

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.

Can you help me understand why is that ?

Edit : Nevermind i found my mistake. I had to remove the " " from true and false.


#5

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