diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 61512aa..4464be2 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -14,11 +14,11 @@ ### 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!") +} - - - - +frozen() @@ -26,32 +26,34 @@ ### 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 phrase = "Let it go!" + print(phrase) +} - - - - +frozenAgain() /*: 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).") +} /*: 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 favoriteCharacter = "Archer" +favoriteCharacter(name: favoriteCharacter) - - - +var anotherCharacter = "Sheeba" +favoriteCharacter(name: anotherCharacter) +anotherCharacter = "Harbinger" +favoriteCharacter(name: anotherCharacter) @@ -59,11 +61,11 @@ ### 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 takeNumbers(number: Int) { + print("I got \(number) problems but Swift ain't one") +} - - - - +takeNumbers(number: 99) @@ -72,35 +74,32 @@ */ // write your code here +func bandFunction(bandName: String, number: Int) { + print("My #\(number) favorite band is \(bandName)") +} - - +bandFunction(bandName: "Aoki", number: 3) /*: 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) /*: 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,9 +111,11 @@ */ // write your code here +func madLib(characterName: String, noun: String, preposition: String) { + print("To \(noun) and \(preposition), \(characterName)!") +} - - +madLib(characterName: "Archangel", noun: "Dog", preposition: "to") @@ -123,7 +124,9 @@ */ // write your code here - +func buzzLightyear() -> String { + return "Buzz Lightyear to the rescue!" +} @@ -133,9 +136,9 @@ ### 11. Create a function that takes no arguments and returns any number. */ // write your code here - - - +func numbers() -> Int { + return 45 +} @@ -144,9 +147,11 @@ */ // write your code here +func beyond(charactersName: String) -> String { + return "To infinity and beyond, \(charactersName.uppercased())!" +} - - +print(beyond(charactersName: "Buzz Lightyear")) //: Click [here](https://github.com/learn-co-curriculum/swift-allAboutFunctions-lab/blob/solution/MyPlayground.playground/Pages/solution.xcplaygroundpage/Contents.swift) for a link to the solution.