Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Jonathon Best
1,588 PointsReturning Values of Functions to Variables
I'm being asked to create a variable named result that returns the tuple assigned to a function's return, but I'm still not getting it...
if the function's return is assigned as -> (greeting: String, language: String), and if I'm supposed to assign that tuple to a variable called result, shouldn't it look like this:
var result = (greeting: String, language: String)
I'm sure it's something super simple that I'm missing, but if you have any insight, let me know.
func greeting(#person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
var result = (greeting: String, language: String)
return greeting(person: "Tom")
}
2 Answers

Greg Kaleka
39,018 PointsHi Jonathon,
You've got a couple of issues with your code, but mostly, you're just over-complicating it for yourself :). Did you pass the first challenge? Your code should have looked like this:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting: greeting, language: language)
}
Then, the second challenge is just asking you to assign the result of calling the greeting function you just defined in the first challenge to a variable result. You need to do this outside the function, not inside, as you've done. We won't change the function at all for this step:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting: greeting, language: language)
}
var result = greeting("Tom") // see how easy that was? :)

Baptiste Fehrenbach
2,227 Pointsvar result = (greeting: String, language: String) return greeting(person: "Tom") You can't declare a tuple like that, watch the video again ! And you're trying to return the result of a function... In this function ! You have to return a variable !
Jonathon Best
1,588 PointsJonathon Best
1,588 PointsTotally cleared a lot of stuff up for me. Thanks for taking the time to answer my question!
Greg Kaleka
39,018 PointsGreg Kaleka
39,018 PointsNo problem! Glad I could help out.