Created
June 20, 2014 00:50
-
-
Save bomatson/73e00b1d5c367c3969db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_for_fizz(number) | |
if number % 5 == 0 and number % 3 == 0 # if the remainder of the number is both divisible by 5 and leaves 0 leftover and divisible by 3 and leaves 0 leftover using the modulo operator, it will print "FizzBuzz" | |
puts "FizzBuzz" | |
elsif number % 5 == 0 # if the remainder of the number is divisible by 5 leaves 0 leftover the program will return the word "Buzz" | |
puts "Buzz" | |
elsif number % 3 == 0 # if the remainder of the number is divisible by 5 leaves 0 leftover the program will return the word "Fizz" | |
puts "Fizz" | |
else | |
puts number # if the number does not fit into any of these equations it returns the integer you selected | |
end | |
end | |
puts "Choose a number from 1 to 100" # I started with a phrase to begin the program | |
number = gets.chomp.to_i # The number is assigned by waiting for user input | |
puts "You have selected #{number}" # I have the program repeat the number along with the following process | |
puts | |
check_for_fizz(number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment