odin-fizzbuzz/index.js

13 lines
390 B
JavaScript
Raw Permalink Normal View History

2024-01-02 18:46:04 +00:00
let number = parseInt(prompt('FizzBuzz: Input a total number'));
if (isNaN(number)) {
alert("Not a number, refreshing");
location.reload();
} else {
for (let i = 1; i <= number; i++) {
output = "";
if (i % 3 === 0) (output += "Fizz");
if (i % 5 === 0) (output += "Buzz");
if (!output) (output = i.toString());
console.log(output);
}
2024-01-02 18:46:04 +00:00
}