Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active February 28, 2016 18:09
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 caseywatts/00bdd95bd27fa66a2ca6 to your computer and use it in GitHub Desktop.
Save caseywatts/00bdd95bd27fa66a2ca6 to your computer and use it in GitHub Desktop.
Fizzbuzz
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment