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 trialRenata Zacarias
553 PointsWhat's wrong with this result variable on the tuple challenge?
Challenge says: Create a variable named result and assign it the tuple retuned from greeting function. Pass the string "Tom".
I created the tuple but when I create the result variable I get an error message saying that my result variable has the wrong value in it and to recheck the instructions. The code seems to work on Xcode. Any ideas on the problem?
Thank you!
func greeting (#person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = ("Hello \(person)")
return (language,greeting)
}
var result = greeting(person: "Tom")
2 Answers
kjvswift93
13,515 PointsYou just need to write it like this:
var result = greeting("Tom")
Elmar Haneveld
1,324 PointsDoing that, but it's not working for me. Can someone help me by showing what I'm doing wrong?
func greeting (#person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language,greeting)
}
var result = greeting("Tom")
Elmar Haneveld
1,324 PointsI fixed this by swapping language and greeting. Not sure if this is a technical mistake or a swift rule.
func greeting (person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Camilo Lucero
27,692 PointsWell done by fixing it, I got stuck exactly in the same point. I don't think this is a Swift rule problem, as it worked perfectly in my Xcode playground.