-
-
Save kaiguogit/6abd9e2edcdff4fd160ffe875e34cfbc to your computer and use it in GitHub Desktop.
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
def fizzbuzz(startnumber,endnumber) | |
#check input for Fixnum | |
if !(startnumber.is_a?(Fixnum) && endnumber.is_a?(Fixnum)) | |
puts "invalid input" | |
return nil | |
end | |
#check start number is smaller than end number | |
if startnumber > endnumber | |
puts "Start number #{startnumber} is greater than end number #{endnumber}, reverting the loop" | |
tmp = endnumber | |
endnumber = startnumber | |
startnumber = tmp | |
end | |
(startnumber..endnumber).each do |i| | |
if i % 5 == 0 && i % 3 == 0 | |
puts "FizzBuzz" | |
elsif i % 5 == 0 | |
puts "Buzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
else | |
puts i | |
end | |
end | |
end | |
fizzbuzz("1050",1000) | |
fizzbuzz(1050,"1000") | |
fizzbuzz(1050,1000) | |
fizzbuzz(1000,1050) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment