FizzBuzz is an extremely common early screening question in interviews for programming jobs.
It is a simple problem that is given with the purpose of filtering out people who simply can't program, without requiring a program with much complexity.
We're going to bump the difficulty up just a bit however to ensure that you can always knock it out of the park on FizzBuzz
Do not search online or use your notes.
This quiz is rare in that it must be done from memory, as it is possible that an interviewer will ask you to complete FizzBuzz in front of them without a reference.
Use RSpec and TDD (write test first, code second) to write a method called fizz_buzz
that does the following:
fizz_buzz
takes a single input argument ofx
- If
x
is divisible by 3, return a string offizz
- If
x
is divisible by 5, return a string ofbuzz
- If
x
is divisible by both 3 and 5, return a string offizzbuzz
3 points are given for the fizz_buzz
method working properly. These are all or nothing, as an employer will not accept a partial solution.
1 point is given for good tests that pass.
1 point is given for excellent style (proper indentation, solid logic)