-
-
Save betsy-nird/2928066 to your computer and use it in GitHub Desktop.
FizzBuzz Homework 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I make it print out nicely?
thx, Betsy