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 trialKris Swanson
1,975 PointsIt keeps saying You need assign the return value of the 'greeting' function to 'result' but i have assigned it that?
I NEED HELP
func greeting(person person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
var result = ("English", "\(name) Tom")
return result
}
3 Answers
neftali
5,294 PointsIt seems you are trying to return a string in that return type. Anything in double quotes "" is a string. You also tried to interpolate the name using a string as the greeting. Here is the code that is the result of your task.
func greeting(person: String) -> (greeting: String, language: String) {
// These are strings, no need to redeclare them in the return type.
let language = "English"
let greeting = "Hello \(person)"
// Simply return both strings in a tuple as stated above with the ( -> ) arrow to return (String, String)
return (language, greeting)
}
Remember that you are returning a tuple of 2 elements. A constant called 'language' and another constant called 'greeting' and you enclose it in parantheses after the return.
Reed Carson
8,306 Pointssince the return type is a tuple, in your function you must also return a tuple. Interpolation is not needed either.
Teodor Garzdin
5,572 PointsYou've specified the return type of the function as a tuple, as seen in your function:
-> (greeting:String, language: String)
If you're not familiar with tuples, I suggest you read the Apple Swift Documentation. The provided link with take you directly to the tuple reference part of the documentation: Tuples