Skip to content

Instantly share code, notes, and snippets.

@betsy-nird
Forked from reneedv/fizz_buzz.rb
Created June 14, 2012 05:01
Show Gist options
  • Save betsy-nird/2928066 to your computer and use it in GitHub Desktop.
Save betsy-nird/2928066 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 % 15 == 0
puts "FizzBuzz"
elsif number % 3 == 0
puts "Fizz"
elsif number % 5 == 0
puts "Buzz"
else
puts number
end
end
end
fizzbuzz
@betsy-nird
Copy link
Author

How do I make it print out nicely?

thx, Betsy

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