Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save charmainetham/2354e405552dda6b84881ba41fc7347d to your computer and use it in GitHub Desktop.
Save charmainetham/2354e405552dda6b84881ba41fc7347d to your computer and use it in GitHub Desktop.
FIZZ BUZZ REFACTORING
#first prompting user
puts "what number would you like to start with"
start = gets.chomp
puts "what number would you like to end with?"
endd = gets.chomp
# Define the variables
(start.to_i..endd.to_i).each do |i|
divby5 = (i % 5 == 0)
divby3 = (i % 3 == 0)
#creating cases
case
when divby5 && divby3
puts "Fizzbuzz"
when divby3
puts "Fizz"
when divby5
puts "Buzz"
else
puts i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment