Created
October 17, 2012 04:00
-
-
Save heptat/3903631 to your computer and use it in GitHub Desktop.
fizzbuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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