Skip to content

Instantly share code, notes, and snippets.

@kahunacohen
Last active March 13, 2023 10:04
Show Gist options
  • Save kahunacohen/d67ae91400909681a3ef8069263b58e0 to your computer and use it in GitHub Desktop.
Save kahunacohen/d67ae91400909681a3ef8069263b58e0 to your computer and use it in GitHub Desktop.
/**
Fizz buzz in JavaScript:
Any number divisible by three, print the word "fizz" and any number divisible
by five print the word "buzz".
Any number divisible by both three and five print "fizz buzz".
*/
for (const n of Array.from(Array(100).keys()).map(n => n + 1)) {
if (n % 15 === 0) {
console.log("fizz buzz");
} else if(n % 3 === 0) {
console.log("fizz");
} else if (n % 5 === 0) {
console.log("buzz");
} else {
console.log(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment