Skip to content

Instantly share code, notes, and snippets.

@quardox
Forked from reneedv/fizz_buzz.rb
Created June 13, 2012 17:33
Show Gist options
  • Save quardox/2925404 to your computer and use it in GitHub Desktop.
Save quardox/2925404 to your computer and use it in GitHub Desktop.
FizzBuzz Homework 1
# Write a Ruby script that prints the numbers from 1-100,
# replacing every multiple of 3 with the word Fizz,
# replacing every multiple of 5 with the word Buzz,
# and replacing every multiple of both with the word FizzBuzz
#
#
def fizzbuzz
array = Array (1..100)
array.each do |number|
if number % 3 == 0 && number % 5 != 0
puts "Fizz"
elsif number % 5 == 0 && number % 3 != 0
puts "Buzz"
elsif number % 5 == 0 && number % 3 == 0
puts "FizzBuzz"
else
puts number
end
end
end
fizzbuzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment