Created
July 19, 2018 12:34
-
-
Save eharrow/0a785c830836b164c9143019ef68d8cd to your computer and use it in GitHub Desktop.
Simple JS FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
"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