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 trialJames Louis
Courses Plus Student 924 Pointswould appreciate some help
I do not fully understand what is needed to be done in this question I understand tuple but stuck on how to answer this question. if someone could break it down to me would really appreciate it
thank you,
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
1 Answer
Steve Hunter
57,712 PointsSure thing!
First task: 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're given a code snippet of:
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
So, we need to modify the code to return a tuple. And the parts of the tuple need to be named, as required in the question. The returned part of the method is defined in the first line after the ->
symbol. We need to tell it that rather than the String it is currently returning, we need it to return a tuple. That is made up of two strings and they're named greeting
& language
.
That gives us (first line only):
func greeting(person: String) -> (greeting: String, language: String) {
Then, the code body needs amending to actually return those things - the return
line needs amending to:
return (greeting, language)
That gives the end method, after the first task, looking like:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
See how you get on with that and shout if you need more!
Steve.