Control Flow code issue


Unexpected token

var isEven = function(number) {
  if(number % 2){
  else if(number !% 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);


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


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:


Thank you for the information. It makes sense now.


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