- 720p
- 540p
- 360p
- 0.50x
- 0.75x
- 1.00x
- 1.25x
- 1.50x
- 1.75x
- 2.00x
We hope you enjoyed this lesson.
Cool lesson, huh? Share it with your friends
About this lesson
Fizzbuzz! is a popular interview question/quiz. Let's build it!
Exercise files
Download this lesson’s related exercise files.
FizzBuzz!60.1 KB FizzBuzz! - Solution
59.5 KB
Quick reference
FizzBuzz!
Let's build FizzBuzz!
When to use
FizzBuzz is a traditional coder interview question, you might get asked it when applying for a job.
Instructions
The idea of FizzBuzz is to print out the number 1 to 100. If a number is divisible by 3, print out FIZZ; if divisible by 5, print out BUZZ; and if divisible by both 3 and 5, print out FIZZBUZZ!
There are many ways to do it, here's one way:
(1..100).each do |num|
if num % 3 == 0 && num % 5 == 0
puts "#{num}. FIZZBUZZ!"
elsif num % 3 == 0
puts "#{num}. Fizz!"
elsif num % 5 == 0
puts "#{num}. Buzz!"
else
puts "#{num}."
end
end
Hints & tips
- FizzBuzz is a popular interview question
Lesson notes are only available for subscribers.