Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Created April 30, 2012 20:58
Show Gist options
  • Save staxmanade/2562639 to your computer and use it in GitHub Desktop.
Save staxmanade/2562639 to your computer and use it in GitHub Desktop.
FizzBuzz - Javascript
var msg;
// FizzBuzz 1
for(var i = 1; i <=100; i++, msg = ''){
if(i % 5 === 0)
msg = 'Buzz';
if(i % 3 === 0)
msg += 'Fizz';
document.write((msg || i) + '</br>');
}
// FizzBuzz 2
for(var i = 1; i <=100; i++, msg = ''){
document.write((((!(i % 5) ? 'Buzz' : '') + (!(i % 3) ? 'Fizz' : '')) || i) + '</br>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment