Stuck at If/Else


#1

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

I want to write a program that checks if a number is even or not. But this is the error I get

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.

And if I declare the variables inside the function, the if statement executes again and again.


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

#2

In our function, that’s where we’re supposed to check if our number (parameter) is evenly divisible by 2. Reread the instructions again, if you need a hint.


#3

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