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 trialZachary Goforth
748 PointsOn Challenge Task 3 how do I use the println function to print the value 'language' for the 'result' tuple?
I know this is a easy task, I'm just having trouble finding an answer.
Here is my guess for the 3rd task... println(result: language)
Obviously I'm using the println function but it's the second part of the 3rd task that i don't understand. Any help is appreciated. :)
func greeting(person: String) -> (greeting : String,language : String ){
let language = "English"
let greeting = "Hello \(person)"
return (greeting ,language)
}
var result = greeting("Tom")
1 Answer
Rasmus Rønholt
Courses Plus Student 17,358 PointsWhen returning tuples with named elements, you can access them using dot notation.
So your print statement should be println(result.language)
Every time you put a colon somewhere it is because you are declaring something - typically the type of a variable/constant/argument (like language: String) - you never use colon to access the values.
Zachary Goforth
748 PointsZachary Goforth
748 PointsI used the println(result.language) and this error showed up...
Bummer! You printed "Hello Tom". It should have printed "English".
I haven't changed my code, I just added the println function.
Rasmus Rønholt
Courses Plus Student 17,358 PointsRasmus Rønholt
Courses Plus Student 17,358 PointsWell that's unfortunate - but I can tell you, that the code is correct. There are only two possible scenarios:
Zachary Goforth
748 PointsZachary Goforth
748 PointsThanks for the help anyway.