Skip to content

Instantly share code, notes, and snippets.

@monsat
Created October 10, 2011 09:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save monsat/1274968 to your computer and use it in GitHub Desktop.
FizzBuzz by JavaScript
Number.prototype.fizzBuzz = function() {
return (this % 3 === 0 ? "Fizz" : "") + (this % 5 === 0 ? "Buzz" : "") || this.toString();
}
// main
for (var i=1; i<=100; i++) {
console.log( i.fizzBuzz() );
}
@monsat
Copy link
Author

monsat commented Oct 10, 2011

コードの分かりやすさでいえば最初のやつかな?短く書くなら2つ目。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment