FizzBuzz was originally a playground game between 2 or more children where they'd take it in turns to call out sequential numbers and replace multiples with words. The common version of this game would see people replacing multiples of 3 with the word "Fizz", multiples of 5 with "Buzz" and common multiples of both with "FizzBuzz".
FizzBuzz became a standard interview question for applicants that showed knowledge of programming theory to test their practical or real world experience with a specific language. They'd be tasked with creating a program to simulate the game of FizzBuzz via an output.
Based off the response from the applicant, the interviewers will be able to gain some insight into how the applicant creates a working program to correctly simulate the outcome.
As mentioned above, the game is rather simple to play. It however has to follow very strict rules.
- The program must count all numbers from 1 to 100
- The program must replace all multiples of 3 with the word "Fizz"
- The program must replace all multiples of 5 with the word "Buzz"
- The program must replace all multiples of 3 and 5 with the word "FizzBuzz"
An example of this is shown below:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
...
The aim of this task is not to create the most efficient way of generating the correct outcome. It is however nice to try and not reuse the same code over and over again as this can show signs of messy code later on when things need to be adapted or added to.
Some extensions to this task are as follows
- Add multiples of 7 to be replaced with the word "Fuzz"
- Add multiples of 11 to be replaced with the word "Bizz"