Hi everyone,
Here's my solution. It's the first one that occurred to me, and it
only took a few mins. to write.
(1..100).each do |n|
if (n % 3) == 0 && (n % 5) == 0
puts "FizzBuzz"
elsif (n % 3) == 0
puts "Fizz"
elsif (n % 5) == 0
puts "Buzz"
else
puts n
end
end
I tried it a few other ways just for fun. I'm happy with this one
that uses 'case.'
(1..100).each do |n|
puts case
when (n % 3 == 0) && (n % 5) == 0: "FizzBuzz"
when n % 3 == 0: "Fizz"
when n % 5 == 0: "Buzz"
else n
end
end
Regards,
Craig