Skip to content

Instantly share code, notes, and snippets.

@ruxandrafed
Created September 2, 2015 06:52
Show Gist options
  • Save ruxandrafed/95f0884470ec574d2bb5 to your computer and use it in GitHub Desktop.
Save ruxandrafed/95f0884470ec574d2bb5 to your computer and use it in GitHub Desktop.
def fizz_buzz_puts(start, finish)
# loops through each number in the range
start.upto(finish) do |number|
puts fizz_buzz(number)
end
end
def fizz_buzz(number)
# checks if number is divisible by both 3 and 5
if div_3?(number) && div_5?(number)
'FizzBuzz'
# checks if number is only divisible by 5
elsif div_5?(number)
'Buzz'
# checks if number is only divisible by 3
elsif div_3?(number)
'Fizz'
# prints numbers not divisible by any
else
number
end
end
# checks if number is divisible by 5
def div_5?(number)
number % 5 == 0
end
# checks if number is divisible by 3
def div_3?(number)
number % 3 == 0
end
a = 60
b = 80
fizz_buzz_puts(a, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment