Tsallaka zuwa abun ciki
Justice Tech School

Practice: FizzBuzz

Combine ranges and case.

Example
puts (1..15).map { |i|
  case
  when i % 15 == 0 then "FizzBuzz"
  when i % 3 == 0 then "Fizz"
  when i % 5 == 0 then "Buzz"
  else i
  end
}.join(" ")

Result

1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

Exercise

Range of 1 to 15.

(115)

Quiz Test

What does case without a value do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.