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

Jerrett Fowler
Jerrett Fowler
3,614 Points

Why is "var result = greeting("Tom")" incorrect? It works in the playground.

I can't tell if I'm totally misreading the challenge or what.

Logan R
Logan R
22,989 Points

Can you please post your code? It will help us find your problem :)

Jerrett Fowler
Jerrett Fowler
3,614 Points
func greeting(person: String) -> (language: String, greeting: String) {
    return (language: "English", greeting: "Hello \(person)")
}
var result = greeting("Tom")

3 Answers

Ethan Lowry
PLUS
Ethan Lowry
Courses Plus Student 7,323 Points

This seems dumb as the code you've provided is valid as far as I can tell, but can you try swapping the order of your arguments in the greeting function? i.e. have greeting then language (and remember to update the order in the return statement too).

This really shouldn't matter, but it might be that the Treehouse challenge specifically is being picky even though your code is technically fine. I did the challenge quickly and did nothing differently from you other than the above, and it worked fine.

...Or, maybe I'm being blind and missing something else :)

Jerrett Fowler
Jerrett Fowler
3,614 Points

That worked. Thank you so much. I feel a bit silly since it was so easy.

You need to initialize the two constants language and greeting. This is what the code should look like...

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

return (greeting, language)

} var result = greeting("Tom")

Jerrett Fowler
Jerrett Fowler
3,614 Points

Sorry Kyle, that doesn't seem to be helping me at all. It's not accepting that, either.

Alejandra González
Alejandra González
947 Points

I need help with task 3 for this challenge! "Using the println statement, print out the value of the language element from the result tuple." Where is this result tuple? I have done the 2 previous tasks right.

Thanks

Logan R
Logan R
22,989 Points

You will most likely be able to get better help for your problem if you make your own question on the forums :)