Skip to content

Instantly share code, notes, and snippets.

@sghall
Created January 18, 2017 07:37
Show Gist options
  • Save sghall/441e2ab9bb45934822b1d4c769fe1e14 to your computer and use it in GitHub Desktop.
Save sghall/441e2ab9bb45934822b1d4c769fe1e14 to your computer and use it in GitHub Desktop.
Fizz Buzz in JavaScript
function fizzBuzz(num) {
for (let i = 1; i <= num; i++) {
const fizz = i % 3 === 0 ? 'Fizz': '';
const buzz = i % 5 === 0 ? 'Buzz': '';
console.log(fizz || buzz ? fizz + buzz: i)
}
};
console.log(fizzBuzz(100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment