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 trialCarlos Loeza
1,139 PointsCreate a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to.
My code no compiler errors but I still can't advance.
func greeting(person: String) -> (language: String, greeting: String) {
let language = ("English", "Hello \(person)")
return language
}
var result = greeting("Tom")
4 Answers
Stepan Ulyanin
11,318 PointsHi, you are returning only one value not 2 as a tuple, you need to specify the tuple at your return statement:
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
JT Keller
12,731 PointsI'm having the same issue and I just copy and pasted your code and it fails as well. I believe you're wrong as the OP's answer is technically returning a tuple.
I tried each of these and they work great in the compiler and the console output is correct as well. Not sure what is wrong.
//func greeting(person: String) -> (language: String, greeting: String) {
//
// let response = (language: "English", greeting: "Hello \(person)")
// return response
//}
//
//let result3 = greeting("Tom")
//println(greeting("Tom"))
//result3.greeting
//result3.language
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello\(person)"
return (language, greeting)
}
let result1 = greeting("Tom")
JT Keller
12,731 PointsBut this works... The exercise didn't state anything about a named parameter as it should if this is the requirement for the code to pass the checks.
func greeting(#person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting(person: "Tom")
Rick Matsumoto
2,547 PointsI think greeting needs to be a variable rather than a constant, but otherwise agree that this code compiles fine and still does not pass the code challenge. The message I get is "Your result
variable has the wrong value in it." I'm stumped!
Rick Matsumoto
2,547 PointsStill not sure I understand what happened, but this passes the code challenge.
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
var greeting = "Hello \(person)"
return (greeting,language)
}
var result = greeting("Tom")
Sam Donald
36,305 PointsYou need to specify person. so....
var result = greeting(person: "Tom")