From a3f2ad61306fca3eef3fccd25c4e71bdb502ed8e Mon Sep 17 00:00:00 2001 From: mainina19 Date: Sat, 15 Dec 2018 18:56:30 -0500 Subject: [PATCH 1/2] Complete problems --- .../main.xcplaygroundpage/Contents.swift | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 61512aa..41cee1e 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -13,7 +13,9 @@ /*: question1 ### 1. Create a function named `frozen` which takes no arguments. When this function is called, it prints "Let it go!". */ -// write your code here +func frozen(){ + print("Let it go!") +} @@ -25,7 +27,11 @@ /*: question2 ### 2. Write a function named `frozenAgain` that takes no arguments. Declare a constant in the body of the function, and assign it the value "Let it go!". Then print it to the console. */ -// write your code here +func frozenAgain(){ + let Constant = "Let it go!" + print("\(Constant)") + +} @@ -36,7 +42,9 @@ /*: question3 ### 3. Write a function that takes in a character's name as an argument (it can be any character from anything). What should the type of that argument be? Print the message "My favorite character is ." to the screen. */ -// write your code here +func favoriteCharacter(name: String){ + print("My favorite character is \(name)") +} @@ -47,7 +55,12 @@ /*: question4 ### 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 character1 = "Rock Lee" +favoriteCharacter(name: character1) +var character2 = "Itachi Uchiha" +favoriteCharacter(name: character2) +character2 = "Orochimaru" +favoriteCharacter(name: character2) @@ -58,10 +71,9 @@ /*: question5 ### 5. Write a function that takes an integer as an argument and prints the string "I got problems but Swift ain't one" to the console. */ -// write your code here - - - +func numProblems(problems: Int){ + print("I got \(problems) problems but Swift ain't one") +} @@ -70,7 +82,9 @@ /*: question6 ### 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, band: String){ + print("My #\(number) favorite band is \(band)." ) +} @@ -80,11 +94,11 @@ /*: 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) @@ -110,9 +124,11 @@ /*: question9 ### 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 madLib(name: String, noun: String, preposition: String){ + print("To \(noun) and \(preposition), \(name)!") +} +madLib(name: "Bob", noun: "House", preposition: "On") @@ -121,7 +137,9 @@ /*: question10 ### 10. Create a function that takes no arguments and returns the string "Buzz Lightyear to the rescue!" */ -// write your code here +func buzz() -> String{ + return "Buzz Lightyear to the rescue!" +} @@ -132,8 +150,9 @@ /*: question11 ### 11. Create a function that takes no arguments and returns any number. */ -// write your code here - +func number() -> Int{ + return 58 +} @@ -142,7 +161,9 @@ /*: question12 ### 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 buzzCharacter(character: String) -> String{ + return "To infinity and beyond, \(character)!" +} From 1e46d495ffe5f83e9161c824fa89403de170e109 Mon Sep 17 00:00:00 2001 From: mainina19 Date: Sat, 15 Dec 2018 19:15:16 -0500 Subject: [PATCH 2/2] misread a question --- .../Pages/main.xcplaygroundpage/Contents.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 41cee1e..26bd666 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -162,7 +162,7 @@ func number() -> Int{ ### 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. */ func buzzCharacter(character: String) -> String{ - return "To infinity and beyond, \(character)!" + return "To infinity and beyond, \(character.uppercased())!" }