diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 61512aa..e0d890d 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -15,7 +15,9 @@ */ // write your code here - +func frozen() { + print("Let it go!") +} @@ -27,7 +29,10 @@ */ // write your code here - +func frozenAgain() { + let letItGo = "Let it go!" + print(letItGo) +} @@ -38,7 +43,9 @@ */ // write your code here - +func charactersName(name: String) { + print("My favorite character is \(name).") +} @@ -48,8 +55,11 @@ ### 4. Call the function you wrote in Question 3 using a constant you define. Then call it using a variable. Change the value of the variable, and call it again. What do you see in the console? */ // write your code here +let Ted = "Ted" +charactersName(name: Ted) - +var Norm = "Norm" +charactersName(name: Norm) @@ -60,7 +70,9 @@ */ // write your code here - +func number(problems: Int) { + print("I got \(problems) but Swift ain't one.") +} @@ -72,19 +84,21 @@ */ // write your code here - - +func band(bandName: String, bandNumber: Int) { + print("My #\(bandNumber) favorite band is \(bandName).") +} +band(bandName: "DoggyDog", bandNumber: 12) /*: question7 ### 7. The code below is broken. Can you identify which line has an error and fix it so that it works again? Uncomment the code below before starting. */ -//func badFavoriteBand(bandName: String, position: Int) { -// print("My #\(position) favorite band is \(bandName).") -//} -// -//badFavoriteBand("The Beatles", 2) +func badFavoriteBand(bandName: String, position: Int) { + print("My #\(position) favorite band is \(bandName).") +} + +badFavoriteBand(bandName: "The Beatles", position: 2) @@ -95,11 +109,11 @@ /*: question8 ### 8. This code is broken, too. Assume the call to the function is correct. What's broken about the function definition? Can you fix it? Uncomment the code below before starting. */ -//func alsoBadFavoriteBand(bandName: String, position: String) { -// print("My #\(position) favorite band is \(bandName)") -//} -// -//alsoBadFavoriteBand(bandName: "Blink-182", position: 42) +func alsoBadFavoriteBand(bandName: String, position: Int) { + print("My #\(position) favorite band is \(bandName)") +} + +alsoBadFavoriteBand(bandName: "Blink-182", position: 42) @@ -112,8 +126,11 @@ */ // write your code here +func madLib(charName: String, noun: String, preposition: String) { + print("To \(noun) and \(preposition), \(charName)!") +} - +madLib(charName: "Fred", noun: "Ball", preposition: "What's a preposition") @@ -123,6 +140,12 @@ */ // write your code here +func buzz() -> String { + return "Buzz Lightyear to the rescue!" +} + +print(buzz()) + @@ -134,8 +157,11 @@ */ // write your code here +func numb() -> Int { + return 29 +} - +print(numb()) @@ -144,8 +170,11 @@ */ // write your code here +func char(name: String) -> String { + return("To infinity and beyond, \(name.uppercased())!") +} - +print(char(name: "Fred"))