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 trial

iOS Swift Functions and Optionals Parameters and Tuples Tuples

Ramon Bonte
Ramon Bonte
1,981 Points

[Swift] Tuples challenge 2 of 3. My code works in Xcode, but not on treehouse

I wrote this code for the challenge:

func greeting(person: String) -> (language: String, greeting: String) {
    let language = "English"
    let greeting = "Hello \(person)"
    return (language: language, greeting: greeting)
}
var result = greeting("Tom")

I seems right to me and Xcode doesn't give any errors or warnings. And variable result stores the tuple returned by greeting. But when i write the same code on treehouse. it keeps saying: β€œBummer! Your result variable has the wrong value in it. Check the task instructions again.” So what is wrong ?

Your code was right. Just the order of the tuples items was wrong.

func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"

return (greeting, language)
}
var result = greeting("Tom")

Question, Im a bit confused as well. Why or how is the order wrong? When you name the elements in the tuple, shouldnt the return tuple be... return (language, greeting) ..? Also what role do the 2 constants play in this? :(

jimi barrolle i really don't know! :(

3 Answers

Bradley Allen
Bradley Allen
5,224 Points

I was recently stuck on this too and would also like to understand why the order is reversed in the return. It doesn't mane any sense.

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Sorry about the inconvenience but the way we are validating the challenge it is expecting the tuples in a certain order. The order is specified in the challenge instructions: Make sure to name each item in the tuple: greeting and language.