samedi 23 mai 2020

is (i % 3 == 0) means ( i % 3 == false )?

I am a beginner learning JS. Can anyone explain to me why "1" on the output?

here it is:

for (var i = 1; i <= 15; i++) {
  if (i % 2 == 0) {
    i += 2;
  } else if (i % 3 == 0) {
    i++;
  }
  console.log(i);
}

output : 1, 4, 5, 8, 10, 11, 14, 16

I can figure out why the output equal to 4, 5, 8, 10, 11, 14, 16 , however, I don't understand why 1 is there as output...

Aucun commentaire:

Enregistrer un commentaire