Skip to content

Instantly share code, notes, and snippets.

@elevenpassin
Created October 25, 2017 17:24
Show Gist options
  • Save elevenpassin/8f92e5249f765484f489095775474cdc to your computer and use it in GitHub Desktop.
Save elevenpassin/8f92e5249f765484f489095775474cdc to your computer and use it in GitHub Desktop.
/*
A program that prints all the numbers from 1 to 100, with two exceptions.
For numbers divisible by 3, it prints "Fizz" instead of the number, and for numbers divisible by 5 (and not 3), it prints "Buzz" instead.
For numbers divisible by both 3 & 5, it prints "FizzBuzz".
TODO:
- Can we make this more progressive/dynamic in any ways?
*/
function fizzBuzz(){
for(var i=1; i <= 100; i++){
if (i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}
}
module.exports = {
fizzBuzz : fizzBuzz
}
/*
A program that prints all the numbers from 1 to 100, with two exceptions.
For numbers divisible by 3, it prints "Fizz" instead of the number, and for numbers divisible by 5 (and not 3), it prints "Buzz" instead.
For numbers divisible by both 3 & 5, it prints "FizzBuzz".
TODO:
- Can we make this more progressive/dynamic in any ways?
*/
function fizzBuzz(){
for(var i=1; i <= 100; i++){
if (i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log("Fizz");
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
console.log(i);
}
}
}
module.exports = {
fizzBuzz : fizzBuzz
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment