Created
May 10, 2013 20:00
-
-
Save ArtBears/5556985 to your computer and use it in GitHub Desktop.
My Ruby Version of 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
#Fizbuzz project | |
=begin | |
Write a program that prints out the numbers 1 to 100 (inclusive). | |
If the number is divisible by 3, print Fizz instead of the number. If | |
it's divisible by 5, print Buzz. If it's divisible by both 3 and 5, | |
print FizzBuzz. | |
=end | |
def fizzbuzz | |
(1..100).each do |x| | |
if x % 3 == 0 && x % 5 == 0 | |
x = "FizzBuzz" | |
puts x | |
elsif x % 3 == 0 | |
x = "Fizz" | |
puts x | |
elsif x % 5 == 0 | |
x = "Buzz" | |
puts x | |
else | |
puts x | |
end | |
end | |
end | |
fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment