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 trialJason Woolard
11,563 PointsParameters and Tuples Quiz Error
In challenge task 1 of 3 in Stage 2 of Parameters and Tuples (Swift Functions and Optional Course) it states to "Currently our greeting function only returns a single value. Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task."
I tried this, which seemed to work in playgrounds as I thought, but kept getting the Bummer! error. Any ideas?:
func greeting(person: String) -> (String, String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
3 Answers
Chris Shaw
26,676 PointsHi Jason,
If you remember back to when Amit was explaining about tuples and naming the values he showed a couple of examples of named return values which are tuples, so what the challenge is asking for is what Amit taught in the previous video.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
One thing Amit doesn't actually teach us it that because these return values are named we can assign them out of order.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language: language, greeting: greeting)
}
Not the best names but it's a nice way to see the power of tuples.
Jason Woolard
11,563 PointsAhh, forgot all about being able to name return values! Thank you sir, you are a genius!
Alejandra González
947 PointsHi, Im stuck with the task 3 for this challenge.
"Using the println statement, print out the value of the language element from the result tuple."
what is the result tuple???? I only have the var result in my code :(