Skip to content

Instantly share code, notes, and snippets.

@heptat
Created October 17, 2012 04:00
Show Gist options
  • Save heptat/3903631 to your computer and use it in GitHub Desktop.
Save heptat/3903631 to your computer and use it in GitHub Desktop.
fizzbuzz
# in this version of FizzBuzz the words have to be separated by a comma
def fizzbuzz(number)
output = nil
if number % 3 == 0
output = "Fizz"
end
if number % 5 == 0
unless output.nil?
output << ", "
output << "Buzz"
else
output = "Buzz"
end
end
if output.nil?
output = number.to_s
end
output
end
(1..100).each do |number|
puts fizzbuzz(number)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment