These are the instructions from Codecademy that need to be followed:
Display the numbers from 1 to 20.
If a number is divisible by 3, show "Fizz".
If a number is divisible by 5, display "Buzz".
If a number is divisible both by 3 and 5, then output "FizzBuzz" in the console.
Otherwise, simply display the number itself.
Here is the code I have prepared:
for (i = 1; i <= 20; i++) {
if (i % 3 == 0) {
console.log("Fizz");
}
else if (i % 5 == 0) {
console.log("Buzz");
}
else if (i % 3 == 0 && i % 5 == 0) {
console.log("FizzBuzz");
}
else {
console.log(i);
}
}
The issue encountered is with printing "FizzBuzz" for the number 15. It only prints "Fizz".
What could be the missing piece here?