1
I am trying to take the test "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! Someone can 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 are most welcome!
Which part doesn’t work?
– rray
When I run the code and see in the Chrome console the numbers don’t appear!
– Rodolpho Bravo
Only appears Fizz, buzz or fizzbuzz you not printing the numbers.
– rray