I'm trying to test the "FIZZBUZZ" which consists of the following:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
I wrote the following code, but it is not working! Can someone give me a light?
var n = 1;
while (n <= 100) {
if ((n % 3) == 0 || (n % 5) == 0) {
if ((n % 3) == 0 && (n % 5) == 0) {
console.log("FizzBuzz");
}
else if (n % 3 == 0 && (n % 5) !== 0) {
console.log("Fizz");
}
else if ((n % 5) == 0 && (n % 3) !== 0) {
console.log("Buzz");
}
else {
console.log(n);
}
}
n = n + 1;
}
If you have suggestions on how to make my code clearer, you will be very welcome!