Final Project: FizzBuzz
FizzBuzz is a classic beginner exercise, and a great way to prove you can combine loops and conditionals.
Requirements
- Loop through the numbers 1 to 100.
- For multiples of 3, print "Fizz" instead of the number.
- For multiples of 5, print "Buzz" instead of the number.
- For multiples of both 3 and 5, print "FizzBuzz".
- For every other number, print the number itself.
Getting started
JavaScript
The % (modulo) operator gives you the remainder of a division, i % 3 === 0 is true exactly when i is a multiple of 3.
Stretch goals
- Rewrite it as a function
fizzbuzz(n)that returns the array of results instead of printing directly. - Support a custom range, e.g.
fizzbuzz(1, 50). - Add a third rule of your own (e.g. multiples of 7 print "Bazz") and combine it correctly with the existing ones.
Submit your code (a repo link or gist) below when you're done, an instructor will review it before you can mark this lesson complete. Welcome to Kodstigen, ready to keep going? 🚀