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 trialRenat Kaitmazov
3,492 PointsWhat should I do in task 2 of 3 Tuples Swift?
It is said here that I have to create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)
Here is my code:
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
And it doesn't work. I don't know why.
4 Answers
agreatdaytocode
24,757 PointsTry this:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Notice the first line
"language: String, greeting: String" vs "greeting: String, language: String"
Nicolás Carelli
2,075 PointsActually, I think there's something wrong there because it said I had an error in:
func greeting(person: String) -> (greeting:String, language:String) { return ("Hello (person)", "language") } var result = greeting("Tom")
BUT NOT IN:
func greeting(person: String) -> (greeting:String, language:String) { return ("Hello (person)", "English") } var result = greeting("Tom")
WHERE "English" and "language" are both strings so...
Nicolás Carelli
2,075 Pointsand in renat and aaron code i think there s not a good re-utilization of parameter names..
Siamak Pourhabib
2,962 PointsHere is the code:
func greeting(person person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting,language) } var result1 = greeting(person: "Tom")
Renat Kaitmazov
3,492 PointsRenat Kaitmazov
3,492 PointsThank you, Aaron.
Sander van Tilburg
Courses Plus Student 2,521 PointsSander van Tilburg
Courses Plus Student 2,521 Pointsjust fixed it