It's beer time!

Post Reply
User avatar
Site Admin
Posts: 31
Joined: Thu Sep 06, 2018 3:17 pm
Location: Cincinnati, Ohio

It's beer time!

Post by jessica » Fri Sep 14, 2018 11:44 am

I've been posting a lot of FizzBuzz examples, although I want to create something a little more interesting. This time it is the Beer song. Notice the variables I have defined, count, containerType and getDrunkBy, these will play a part in the creation of the song. Also there is a function called getDrunkBy which will shuffle the 3 sentence in the song as if they were getting drunk. Have fun and enjoy.

puts; puts " It's beer song time!"; puts

@count = 99
@containerType = "bottle"
@getDrunkBy = @count - 10

def container(n, container)
n == 1 ? "#{n} #{container}" : "#{n} #{container}s"

def getDrunk(str, n, by)
by <= n ? str : str.split(' ').shuffle.join(' ').capitalize

@count.downto(1) {
#{container(@count, @containerType)} of beer on the wall
#{container(@count, @containerType)} of beer
#{getDrunk('Take one down pass it around', @count, @getDrunkBy)}
#{container(@count -= 1, @containerType)} of beer on the wall

puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts; puts " No more beer on the wall :-("
puts " And I'm on the floor"
Post Reply