Why the else if condition still executes when the if condition is already true? I thought if the if condition is true anything under it like else if...else or else will be worthless. code:
for (i = 1; i <= 20; i++)
{
if (i % 3 === 0 && i % 5 === 0)
{
console.log("FizzBuzz");
}
else if (i % 3 === 0)
{
console.log("Fizz");
}
else if (i % 5 === 0)
{
console.log("Buzz");
}
else
{
console.log(i);
}
}
this is the output
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Aucun commentaire :
Enregistrer un commentaire