diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 61512aa..8b177c3 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -15,8 +15,12 @@ */ // write your code here +func frozen () +{ + print("Let it go!") +} - +frozen() @@ -27,7 +31,13 @@ */ // write your code here +func frozenAgain () +{ + let message = "Let it go" + print(message) +} +frozenAgain() @@ -38,8 +48,11 @@ */ // write your code here - - +func charName (name: String) +{ + print("My favorite character is \(name)") +} +charName(name: "daffy") @@ -49,6 +62,14 @@ */ // write your code here +let cName = "Mickey" +charName(name: cName) + +var cNameVar = "Mini" +charName(name: cNameVar) + +cNameVar = "Superman" +charName(name: cNameVar) @@ -60,8 +81,12 @@ */ // write your code here +func problems (numProblems: Int) +{ + print ("I got \(numProblems) problems but Swift ain't one") +} - +problems(numProblems: 3) @@ -71,20 +96,23 @@ ### 6. Write a function that takes two arguments, the name of a band (a `String`) and a number (an `Int`). It should print the message "My # favorite band is ." to the console. */ // write your code here +func favBand (number: Int, isBandName: String) +{ + print("My #\(number) favorite band is \(isBandName)") +} - - +favBand(number: 2, isBandName: "Envogue") /*: 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 +123,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) @@ -111,9 +139,12 @@ ### 9. Let's play Mad Libs! Create a function called `madLib`. It should take three parameters: A character name, a noun, and a preposition, and print out the line "To and , !" to the console. Don't forget to call your function to test it out! */ // write your code here +func madLibs (crName: String, noun: String, preposition: String) +{ + print("To \(noun) and \(preposition), \(charName)") +} - - +madLibs (crName: "Scooby", noun: "cow", preposition: "upon") @@ -123,7 +154,11 @@ */ // write your code here - +func buzz () -> String +{ + let lightYear = "Buzz LightYear to the rescue!" + return lightYear +} @@ -134,8 +169,15 @@ */ // write your code here +func retNumber () -> Int +{ + let num: Int = 43 + + return num + +} - +retNumber () @@ -143,7 +185,12 @@ ### 12. Create a function that takes in a characters name. This function will return back a `String` as follows: "To infinity and beyond, !". The character name should be returned uppercased. */ // write your code here - +func charName2 (name: String) -> String +{ + name.uppercased() + let newString = "To infinity and beyone, \(name)!" + return newString +}