Created
September 25, 2013 15:04
-
-
Save TrevMcKendrick/6700974 to your computer and use it in GitHub Desktop.
This file contains 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
#1 Define a fizzbuzz method to do the following: | |
def fizzbuzz_it(number) | |
if number % 3 == 0 && number % 5 == 0 | |
return "FizzBuzz" | |
elsif number % 3 == 0 | |
return "Fizz" | |
elsif number % 5 == 0 | |
return "Buzz" | |
end | |
end | |
# 2 Write a loop that will group the numbers from 1 through 50 | |
# by whether the fizz, buzz or fizzbuzz. | |
def group | |
fizz = [] | |
buzz = [] | |
fizzbuzz = [] | |
for each_number in 1..50 do | |
if fizzbuzz_it(each_number) == "Fizz" | |
fizz << each_number | |
elsif fizzbuzz_it(each_number) == "Buzz" | |
buzz << each_number | |
elsif fizzbuzz_it(each_number) == "FizzBuzz" | |
fizzbuzz << each_number | |
end | |
end | |
puts "These numbers Fizz " + fizz.to_s | |
puts "These numbers Buzz " + buzz.to_s | |
puts "These numbers FizzBuzz " + fizzbuzz.to_s | |
end | |
group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment