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 trialCameron Brannelly
1,639 PointsMy function returns a tuple that includes both "language and greeting." I have no compiling issues. What am I missing?
?
func greeting(person: String) -> (String, String) {
let language = "English"
let greeting = "Hello \(person)"
var tuple = (greeting, language)
return tuple
}
2 Answers
Cameron Brannelly
1,639 PointsThanks, that was it. I had tried just including them in the return result instead of creating the tuple variable, but did not name the return parameters.
Chase Marchione
155,055 PointsHi Cameron,
1) Try naming the return parameters 'greeting' and 'language' in your function header. This will name them in the tuple.
2) Instead of creating a variable named tuple, you can return the values of both of those constants by use of parentheses in your return statement. (Although this isn't necessary, it lessens the number of lines in the code, and eliminates an extra step.)
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
Hope this helps!