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 trialAristotle M
1,537 PointsI can't figure out objective 3:
Challenge is: Using the println statement, print out the value of the language element from the result tuple.
func greeting(person: String) -> (greeting : String,language : String ){
let language = "English"
let greeting = "Hello \(person)"
return (greeting ,language)
}
var result = greeting("Tom")
println()
6 Answers
Kieran Tross
8,266 Pointsthat doesn't work. i think you have to pass more result options within the result parameter.
Kieran Tross
8,266 Pointsyou have to pass the "println(language) within the greeting function. This has to be applied within the greeting function scope.
krilnon
1,458 PointsI don't think that's what they want. I think they expect something like:
func greeting(person: String) -> (greeting:String, language:String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
let result = greeting("Tom")
println(result.language)
Kieran Tross
8,266 Pointsno that didn't work. You have to apply the "println(language) above the first return statement.
Kieran Tross
8,266 PointsDid you try what i stated? The below works.
func greeting(person: String) -> (greeting:String , language:String) { let language = "English" let greeting = "Hello (person)" println(language)
return (greeting, language)
}
var result = greeting("Tom")
Jhoan Arango
14,575 PointsThere seems to be an error in this challenge. But to pass the challenge it has to be this way. Even tho this is not correct.
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language) // the error seems to be here
}
var result = greeting("Tom”)
println(result.greeting)
The correct way of doing it is like this, but it won’t pass the challenge for some reason.
func greeting(person: String) -> (language:String,greeting:String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting) // Corrected
}
var result = greeting("Tom")
result.greeting // will print “Hello Tom”
result.language // will print “English"
krilnon
1,458 Pointsprintln(result.language)