Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdam Wessell
1,154 PointsI still don't understand
Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)
func greeting(person: String) -> (language: String, greeting:String) {
var result = (language, greeting)
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
greeting("Tom")
1 Answer
Ryan Hoffmann
7,815 PointsYour function would look like this:
func greeting(person: String) -> (language: String, greeting:String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
As you can see, the method grabs the persons name that you pass into the function, and then uses String interpolation to include the value stored in the "person" parameter into the greeting String. You then return a tuple containing the language and greeting.
The below "result" variable is then assigned the value that is returned from the "greeting" method (outside of the above function), which as mentioned above, is the tuple containing the language and greeting.
var result = greeting("Tom")
So the full thing could look like this:
func greeting(person: String) -> (language: String, greeting:String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
println("Greeting: \(result.greeting)") //to test that the assignment worked!
Hope this helps!
Adam Wessell
1,154 PointsAdam Wessell
1,154 PointsThank you Ryan! Was a huge help!