Skip to content

Instantly share code, notes, and snippets.

@huezoaa
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huezoaa/741e3d30c58bf236b408 to your computer and use it in GitHub Desktop.
Save huezoaa/741e3d30c58bf236b408 to your computer and use it in GitHub Desktop.
FizzBuzz
# Method fizzbuzz will have a default num parameter of 15
# so if I call it by mistake without passing a value, it will return
# "fizzbuzz" and I will know where to look in my code.
def fizzbuzz(num=15)
# Check for the most intricate condition first!
if (num % 3 == 0) and (num % 5 == 0)
puts "FizzBuzz!!!!!!"
# puts "Fizz" if the number is a multiple of 3
elsif num % 3 == 0
puts "Fizz"
# puts "Buzz" if the number is a multiple of 5
elsif num % 5 == 0
puts "Buzz"
# puts the number itself, if it's not a multiple of 3 or 5
else
puts num
# end of If statement
end
# end of method definition
end
# Call the method for numbers from 1 to 100.
(1..100).each do |number|
fizzbuzz(number)
sleep 0.1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment