Skip to content

Instantly share code, notes, and snippets.

@jakeboxer
Created September 3, 2012 00:07
Show Gist options
  • Save jakeboxer/3605769 to your computer and use it in GitHub Desktop.
Save jakeboxer/3605769 to your computer and use it in GitHub Desktop.
FizzBuzz Test
Write a program that prints the numbers from 1 to 100. But for multiples of
three print “Fizz” instead of the number and for the multiples of five print
“Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
So, for example, if you were to print from 1 to 20, it would look like this:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
@naveedehmad
Copy link

def fizz_buzz
  numbers = 1..100
  numbers.each do |n|
    if n % 15 == 0
      puts "FizzBuzz"
    elsif n % 5 == 0
      puts "Buzz"
    elsif n % 3 == 0
      puts "Fizz"
    else
      puts n
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment