From b4efa611f0332dd28fdc72e0607a17daa2e225d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cdnomyar105=E2=80=9D?= Date: Sat, 24 Nov 2018 15:06:45 -0500 Subject: [PATCH] Complete problems --- .../main.xcplaygroundpage/Contents.swift | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 09e428b..c607fd8 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -11,41 +11,62 @@ /*: 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 - - +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 happyDays() { + let friday = "TGIF" + print(friday) +} +happyDays() /*: 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 nameSearch(name: String) { + print("Welcome \(name)") +} +nameSearch(name: "Raymond") /*: 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 - +var bestName = "Shih" +nameSearch(name: bestName) +bestName = "Wang" +nameSearch(name: bestName) /*: question5 ### 5. Write your own function in which you declare a _variable_ (of any type) inside the function's body. Print out this variable to the console from within your function. After you print the variable once, assign a new value to this variable on the next line. Print it again (after the line on which you assign it to a new value). Call your function several times. What do you expect to see printed to the playground's console each time you call this function? */ -// write your code here - - +func speedTest(speed: Int) { + print(speed) +} + +speedTest(speed: 30) +speedTest(speed: 45) +speedTest(speed: 50) + +func helloVariable() { + var greeting = "Hello" + print("\(greeting), world!") + greeting = "Guten Tag" + print("\(greeting), world!") +} + +helloVariable() +helloVariable() +helloVariable() //: 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.