Skip to content

Instantly share code, notes, and snippets.

@hudsonfoo
Last active December 20, 2015 16:59
Show Gist options
  • Save hudsonfoo/6165934 to your computer and use it in GitHub Desktop.
Save hudsonfoo/6165934 to your computer and use it in GitHub Desktop.
FizzBuzz
for (var i = 1; i <= 100; i++) {
document.write(((i % 3 === 0 ? 'Fizz':'') + (i % 5 === 0 ? 'Buzz':'')) || i);
}

Today's Kata: FizzBuzz

General Kata Concepts

  • Write beautiful code, and comment when necessary to help explain to others what you've done
  • Each Kata has its own goals. Sometimes you'll want to create the least amount of code necessary. Other times you'll want to create the most efficient code.
  • Kata is about learning new techniques. Be original. Be innovative. Learn something. Teach something.

About this Kata

FizzBuzz is an old school kata that we found from the awesome CODING HORROR website, found here: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html

It's a great first question in an interview. I've been asked similiar questions in interviews, so be ready!

Instructions

  1. Print the numbers from 1 to 100.
  2. For every number divisible by 3, print "Fizz" instead of the number.
  3. For every number divisible by 5, print "Buzz" instead of the number.
  4. For every number divisible by 3 and 5, print "FizzBuzz" instead of the number.
  5. Once you've completed your code, edit this Gist, add a new file (use your name/username for the filename), select your code type and paste your code.
  6. Come back to the CodeKata.co website, and link to your revision in the comments.
  7. ???
  8. PROFIT!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment