Created
November 4, 2013 19:48
-
-
Save josephdburdick/7308199 to your computer and use it in GitHub Desktop.
This file contains 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
class BottlesOfBeer | |
def count_off | |
puts "How many bottles of beer have you got?" | |
numbers = gets.chomp.to_i | |
word_bottles = "bottles" | |
numbers.downto(1) do |number| | |
puts "\n#{number} #{word_bottles} of beer on the wall" | |
puts "#{number} #{word_bottles} of beer!" | |
puts "You take one down and pass it around," | |
next_num = number-1 | |
last_line = " of beer on the wall!" | |
if next_num == 1 | |
word_bottles = word_bottles.chop | |
end | |
if next_num == 0 | |
word_bottles = "No more bottles" | |
end | |
if next_num > 0 | |
puts "#{next_num} " + word_bottles + last_line | |
else | |
puts "No more bottles" + last_line.chop + " :-(" | |
end | |
end | |
end | |
bottle = BottlesOfBeer.new | |
bottle.count_off | |
end | |
# Write a program that prints 99 bottles of beer on the wall. | |
# The song starts with | |
# 99 bottles of beer on the wall | |
# 99 bottles of beer! | |
# You take one down and pass it around, | |
# 98 bottles of beer on the wall! | |
# | |
# And ends with | |
# 1 bottle of beer on the wall | |
# 1 bottle of beer! | |
# You take one down and pass it around, | |
# No more bottles of beer on the wall :-( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment