r/learnruby • • Apr 14 '14

FizzBuzz

I was looking at fizzbuzz examples and I wrote my own today. I wanted some feedback and see if there's anything I can do to improve my code. Also interested in seeing other people's examples!

Here's my code:

def fizzbuzz(count)
  (count+1).times do |num|
    print "Fizz" if num%3 == 0 unless num==0
    print "Buzz" if num%5 == 0 unless num==0
    print num if num%3 != 0 && num%5 != 0
    puts ""
  end
3 Upvotes

5 comments sorted by