diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index 09e428b..c4fd702 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -11,7 +11,10 @@ /*: 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() @@ -19,7 +22,11 @@ /*: 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 myFunction(){ + let myConstant = "Constant" + print(myConstant) +} +myFunction() @@ -27,23 +34,35 @@ /*: 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 greeting(name: String){ + print("Hello, \(name).") +} +greeting(name: "Adrian") +greeting(name: "Brian") +greeting(name: "Anthony") /*: 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 - +let name = "Chuck" +greeting(name: name) /*: 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 newFunction(){ + var myNumber = 8 + print(myNumber) + myNumber = 9 + print(myNumber) +} +newFunction() +newFunction() +newFunction() diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/timeline.xctimeline b/MyPlayground.playground/Pages/main.xcplaygroundpage/timeline.xctimeline new file mode 100644 index 0000000..bf468af --- /dev/null +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + + diff --git a/MyPlayground.playground/contents.xcplayground b/MyPlayground.playground/contents.xcplayground index 5ed2911..5b42177 100644 --- a/MyPlayground.playground/contents.xcplayground +++ b/MyPlayground.playground/contents.xcplayground @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file