Stuck and need help with return - possibly more of my code


#1

What am I doing wrong? Am I logging with return wrong, or is more of my code wrong? I just started this section of the course. Any help would be appreciated :slight_smile:


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


"Looks like your function returns false when number = 2. Check whether your code inside the if/else statement correctly returns true if the number it receives is even."


 if (isEven % 2){
     return true
 } else {
     return false
 }

Thanks everyone,
Jacob


#2

Can you post all of your code so far?


#3

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

};


#4

the if statement needs a boolean result, you're doing an operation that produces in a number.


#5

You want the if statement to return true and the else statement to return false.

Your if condition should compare the result of number%2 with 0, like this:

if(number%2===0)

Let's pretend number above is 2, it gets divided by 2 and has a remainder of 1. 1 is not equal to 0, so it is false and the else statement would trigger.


#6

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