Control Flow code issue


#1


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


Unexpected token


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


#2

To check if a number is true the syntax is, number % 2 === 0 not number % 2.

and here

You should replace this with an else statement like,

else {
    return (false);
}

#3

Can you explain why it has to be number % 2 === 0 please? I don't quite understand this.


#4

In most if not all languages that is way of checking for even numbers, with exceptions to number of equal signs used. :slight_smile:

And so by knowing that you can simply check for odd numbers by writing,

number % 3 === 0

The === 0 part means that when that number is divided and divided down to its GCF it should be ann odd number or 0. :slight_smile:


#5

Thank you for the information. It makes sense now.


#6

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