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 trialMohammad Rehman
Courses Plus Student 2,416 Pointshow do i do this task
2 Answers
Steve Hunter
57,712 PointsHi Mohammed,
The first stage requires you to modify what the existing function returns into a tuple, with appropriate names.
You start out with
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
which is a function returning a String. To amend that, add the two Strings it now needs to return, while naming them. We also need to actually return the tuple! So, a couple of amendments in the method implementation and return statement.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
That should get you through the first bit of code; let me know if you need a hand with the rest of the challenge.
Steve.
Steve Hunter
57,712 PointsSure!
The second part asks you to create a variable called result
. So that's var result =
something. THe value of result should be what the greeting
function returns. That function takes a String as a parameter - the questions asks that it be passed the string Tom
. The line of code that does that looks like:
var result = greeting("Tom")
Next up, the challenge is to print out "the language element". The greeting
function returns a tuple - that has more than one part to it. In this case, greeting
and language
. We only want to print out the language
bit. You can use dot notation to access each element of the tuple:
println(result.language)
So, that's it! I hope you understand that - just shout it not.
Steve.
Mohammad Rehman
Courses Plus Student 2,416 PointsMohammad Rehman
Courses Plus Student 2,416 Pointscan i get help with the second and the third part, I have been trying to do it for a long time?