Skip to content

Instantly share code, notes, and snippets.

@Chiamaka
Created December 1, 2017 00:52
Show Gist options
  • Save Chiamaka/edf3c5fc6084ce1f5c3ca1313069670b to your computer and use it in GitHub Desktop.
Save Chiamaka/edf3c5fc6084ce1f5c3ca1313069670b to your computer and use it in GitHub Desktop.
Print out lyrics to the 99 bottles song using swift http://www.99-bottles-of-beer.net/lyrics.html
import UIKit
func bottlesLyrics(numberOfBottles: Int) {
for bottles in (1...numberOfBottles).reversed() {
let bottlesMinusOne = bottles - 1
let bottleTag = bottles == 1 ? "bottle" : "bottles"
var computedString = ""
if bottlesMinusOne == 0 {
computedString = "no more bottles"
} else if bottlesMinusOne == 1 {
computedString = "\(bottlesMinusOne) bottle"
} else {
computedString = "\(bottlesMinusOne) bottles"
}
print ("""
\(bottles) \(bottleTag) of beer on the wall, \(bottles) \(bottleTag) of beer.
Take one down and pass it around, \(computedString) of beer on the wall
"""
)
}
print ("""
No more bottles of beer on the wall, no more bottles of beer
Go to the store and buy some more, \(numberOfBottles) bottles of beer on the wall
""")
}
bottlesLyrics(numberOfBottles: 99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment