Tuesday, 8 November 2011

FizzBuzz in Ruby


def fizzBuzzMe(input)
if input % 15 == 0
'FizzBuzz'
elsif input % 5 == 0
'Buzz'
elsif input % 3 == 0
'Fizz'
else
input
end
end


#tests
#puts fizzBuzzMe(1)
#puts fizzBuzzMe(2)
#puts fizzBuzzMe(3)
#puts fizzBuzzMe(5)
#puts fizzBuzzMe(15)


for i in (1..100)
puts fizzBuzzMe(i)
end
gets

No comments:

Post a Comment