Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Problems #607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,48 @@
/*: 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 printSalutations() {
let salutation = "Good Day!"
print(salutation)
}

printSalutations()
/*: 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 sayHello(to name: String) {
print("Hello \(name)!")
}

sayHello(to: "Brett")
sayHello(to: "Valerie")
sayHello(to: "Holly")
sayHello(to: "Kamryn")
sayHello(to: "Teagan")
/*: 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 founderName = "Avi"
sayHello(to: founderName)
founderName = "Mike"
sayHello(to: founderName)
/*: 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 changeValues() {
var someValue = "Time"
print(someValue)
someValue = "Money"
print(someValue)
}

changeValues()
//: 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.