From 5763196ba2eeeda37bd02425f377ccece6fd7120 Mon Sep 17 00:00:00 2001 From: nyamburanjuguna Date: Thu, 29 Apr 2021 11:43:23 +0300 Subject: [PATCH] added Solution to optional Challenge 2 --- 4-loops/99-bottles/FiveLittleMonkeys.swift | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/4-loops/99-bottles/FiveLittleMonkeys.swift b/4-loops/99-bottles/FiveLittleMonkeys.swift index 7c5f0cf..b970346 100644 --- a/4-loops/99-bottles/FiveLittleMonkeys.swift +++ b/4-loops/99-bottles/FiveLittleMonkeys.swift @@ -19,3 +19,31 @@ print ("\(numMonkeys) little monkey jumping on the bed.") print ("They fell off and bumped their head!") print ("Mama called the doctor and the doctor said") print ("'Put those monkeys straight to bed!'") + + +// Solution to optional challenge 2 + +/* +// numOfMonkeys represents number of monkeys on bed +var numOfMonkeys: Int = 5 + +// Lyrics will print and decrease from 5 to the last one +for numOfMonkeys in stride(from: 5, to: 0, by: -1) { + + // "line[number]Lyric" represents the line of the lyric on a verse + let line1Lyric: String = "\n\(numOfMonkeys) little Monkeys jumping on the bed..." + let line2Lyric: String = "\nOne fell off and bumped her head..." + let line3Lyric: String = "\nMama called the doctor and the doctor said..." + let line4Lyric: String = "\n'Hello? No more Monkeys jumping on the bed!'" + + // Print the lyric iteration + print("\(line1Lyric) \(line2Lyric)\(line3Lyric)\(line4Lyric)") +} + +// Last lyric +var lastVerse: String = "\nNo little Monkeys jumping on the bed...\nThey fell asleep while laying their heads...\nDoctor called Mama and Mama said...\n'Hello? No more Monkeys jumping on the bed!'" + +// Print the final lyrics +print("\(lastVerse)") + +*/ \ No newline at end of file