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 trialSON VO
6,165 PointsI got stuck with this task. Need help!
Guys! How to assign the tuple to var result?
func greeting(person: String) -> (greeting:String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
let greet = (greeting, language)
return greet
}
1 Answer
Greg Kaleka
39,021 PointsHi SON VO,
Your code looks good so far. Do you see how the function you've defined takes a string and returns a tuple? Challenge 2 wants you to assign the result of that function (which is a tuple) to a variable called result
. You probably know this already, but when you assign things to a variable, that just means setting a variable equal to something.
var something = "a great string"
Assigns the string "a great string" to the variable something
.
In this case, since we want to assign the result of a function to a variable, we follow the same pattern:
var result = greeting("Tom")
Note that this line will go outside the function definition, since we're done defining it and now we want to use it.
Let me know if that helps!
SON VO
6,165 PointsSON VO
6,165 PointsThank for your help Greg. I also got stuck with task 3: how to print out language element from the result.
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsHey Son,
It sounds like you're having a lot of trouble - I would recommend watching the video again, keeping in mind the tasks you need to be able to complete.
Let us know what you've tried after watching again and giving it another shot.
Good luck!