FizzBuzz
Objectives
- Declare a
for
loop to perform a hardcoded set of iterations. - Use
if
,else if
, andelse
statements to define various behaviors based upon the loop's counter variable. - Move the loop's iteration logic from hardcoded values into variables instead.
Advanced
- Attempt your own solution to the FizzBuzz exercise that repeats neither the conditional logic nor instructions.
- Follow best practice by using variables instead of "magic numbers" in the conditional logic.
Instructions
FizzBuzz is a classic programmer's exercise. It originated from a children's word game used to teach division. The rules are simple: a sequence of numbers is counted out, but every number divisible by three is replaced with "Fizz", every number divisible by five is replaced with "Buzz", and every number divisible by both three and five is replaced with "Fizz" and "Buzz". A correct recitation of the sequence would follow this pattern:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz,
16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz,
31 ...
Note: Don't focus on writing the perfect implementation of FizzBuzz.
View FizzBuzz on Learn.co and start learning to code for free.