Skip to content

Instantly share code, notes, and snippets.

@eharrow
Created July 19, 2018 12:34
Show Gist options
  • Save eharrow/0a785c830836b164c9143019ef68d8cd to your computer and use it in GitHub Desktop.
Save eharrow/0a785c830836b164c9143019ef68d8cd to your computer and use it in GitHub Desktop.
Simple JS FizzBuzz
/*
"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”."
*/
// range fill
let numbers = [];
for(i = 0; i < 100; i++) {
let c = i + 1;
numbers.push(c);
}
numbers.forEach(function(n) {
let match = false;
if (n % 3 === 0) {
process.stdout.write(`Fizz`);
match = true;
}
if (n % 5 === 0) {
process.stdout.write(`Buzz`);
match = true;
}
if (!match) {
process.stdout.write(`${n}`);
}
process.stdout.write(`\n`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment