Skip to content

Instantly share code, notes, and snippets.

@sk187
Last active February 28, 2016 18:11
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 sk187/e6181b10af70b8bf9123 to your computer and use it in GitHub Desktop.
Save sk187/e6181b10af70b8bf9123 to your computer and use it in GitHub Desktop.
fizzbuzz Challenge
def fizzbuzz(x)
# your
# code
# goes
# here
puts "(change me I am a placeholder string)"
end
# Tests
puts "Should be 'Fizz'"
fizzbuzz(3)
puts "" # newline
puts "Should be 'Buzz'"
fizzbuzz(5)
puts "" # newline
puts "Should be 'Fizzbuzz'"
fizzbuzz(15)
puts "" # newline
puts "Should be 'boring number'"
fizzbuzz(1)
puts "" # newline
# Given the arugment x
# If x is divisible by only 3 return "Fizz"
# If x is divisible by only 5 return "Buzz"
# If x is divisible by 3 and 5 return "Fizzbuzz"
# If x is not divisible by 3 or 5, return "boring number"
# Bonus
# If you finish the assignment early
# for numbers 1 to 100, print out the number and whether it is "fizz" or "buzz" or "fizzbuzz" or "boring number"
# for example "1: Fizz"
# Hint: use "(1..100).to_a" to get an array of the numbers from 1 to 100
# Bonus 2
# If you finsh the first bonus try doing everything without modulus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment