From 768bfd6b6586d5b548ad7ca1701e42b5cabd2eab Mon Sep 17 00:00:00 2001 From: Kegan Date: Thu, 18 Oct 2018 17:29:53 +0800 Subject: [PATCH] Update MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift --- .../main.xcplaygroundpage/Contents.swift | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 09e428b..2b56a93 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -11,32 +11,46 @@ /*: question1 ### 1. Write a function called `helloWorld()` that prints "Hello, world!" to the console. Then call it to see your string printed to the playground console. */ -// write your code here - +// write your code her +func helloWorld(){ + + print("Hello, world!") + +} +helloWorld() /*: question2 ### 2. Write your own function in which you declare a constant inside the function's body and then print that constant to the console. Call this function to see your string printed to the playground console. */ // write your code here +func constantPractice(){ + let name = "Kegan" + print(name) +} - - +constantPractice() /*: question3 ### 3. Write a function that takes a person's name as an argument and prints a greeting to the console. Call it several times with different arguments. What do you think you'll see in the console? */ // write your code here +func greetGuest(name: String){ + print("Hello, \(name). Welcome to Earth!") +} - - +var guest1 = "Greg" +greetGuest(name: "Charlie") +greetGuest(name: "Marvin") +greetGuest(name: guest1) /*: question4 ### 4. Now call the function you wrote in Question 3 using a variable or constant instead of a string literal. What do you expect to see in the console? Try passing in a _variable_ you declared (using `var`) as an argument. Then change that variable's value and call your function again. What do you see in the console? */ // write your code here - +guest1 = "Tom" +greetGuest(name: guest1) @@ -45,7 +59,13 @@ */ // write your code here +func returnNumbers(){ + var num = 10 + print(num) + num = 25 + print(num) +} - - +returnNumbers() +returnNumbers() //: Click [here](https://github.com/learn-co-curriculum/swift-functionLab-lab/blob/solution/MyPlayground.playground/Pages/solution.xcplaygroundpage/Contents.swift) for a link to the solution.