Skip to content

Instantly share code, notes, and snippets.

@mjmeilahn
Last active May 29, 2020 15:47
Show Gist options
  • Save mjmeilahn/4acb925209be5a7bd2d301c65e3370c7 to your computer and use it in GitHub Desktop.
Save mjmeilahn/4acb925209be5a7bd2d301c65e3370c7 to your computer and use it in GitHub Desktop.
JS: Fizzbuzz Function
// DESCRIPTION
// Counting from 0 to 100, print out each number in the console.
// RULES
// 1. If the number is a multiple of 3, print "fizz" instead of the number.
// 2. If the number is a multiple of 5, print "buzz" instead of the number.
// 3. If the number is a multiple of both 3 and 5, print "fizzbuzz" in place of the number.
// 4. Otherwise just print the number itself.
// 5. Each entry should be printed on a new line.
const fizzbuzz = () => {
for (let i = 0; i <= 100; i++) {
if (i % 5 === 0 && i % 3 === 0) {
console.log('fizzbuzz');
}
else if (i % 3 === 0) {
console.log('fizz');
}
else if (i % 5 === 0) {
console.log('buzz');
}
else {
console.log(i);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment