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

Sabhya Chhabria
Sabhya Chhabria
1,312 Points

How to do this question

Im not being able to solve this, pls help

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

    return greeting
    }

2 Answers

J.D. Sandifer
J.D. Sandifer
18,813 Points

It looks like there are three things you need to change: 1) the return type needs to be a tuple, 2) you need to return greeting and language as the tuple (in the return statement), and 3) if I remember right, language does not belong in the text you assign to greeting.

Remember, tuples look like this: (firstItem, secondItem)

I will show you the correct code then try to explain how it differs from your answer

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

    return (greeting, language)
}

var result = greeting("Tom")

Your return type needs to be a tuple of type (String, String), that uses the strings for greeting and language as it's parameters. Then in the return statement, you must return both greeting and language as the return is specified at the top in the function greeting. Returning (language, greeting) correctly matches the form of a tuple.