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

Joshua De La Rosa
Joshua De La Rosa
2,721 Points

Having trouble no matter what i try i can't assign the return value to result. IN Task 2

in task 2 of the quiz it asks me to create a variable result and assign the return value to result. Ive tried a lot and it tells me same thing you need to assign return value greeting to result.

Can some one please teach me the code to do this

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

    return (greeting, language)
}
    let result = greeting

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Joshua,

The question for task 2 is as follows:

Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)

What this means is we need to create a variable called result and assign is the return value of greeting which means we need to call this function and pass it the argument Tom as the parameter.

var result = greeting("Tom")

Happy coding!

Joshua De La Rosa
Joshua De La Rosa
2,721 Points

thank you very much i feel dumb now and can now see what i was doing wrong

Chris Shaw
Chris Shaw
26,676 Points

No worries, also this has happened to a number of other students too, it's just the process of learning :smile:

This is still currently failing in Treehouse editor.

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

    return (language, greeting)
}

var result = greeting("Tom")

Gets the error

Bummer! You need assign the return value of the 'greeting' function to 'result'