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 trialJake N
612 Pointslost
im not sure how to solve this one
func greeting(person: String) -> (greeting: String, language: string) {
let language = "english"
let greeting = "Hello \(Tom)"
return (greeting, language)
}
3 Answers
Chris Shaw
26,676 PointsHi Jake,
You have a first problems with your code.
- In your return type, the type
string
set for language is incorrect, it should have a capital S - the e in English needs to be capital
- your
greeting
constant needs to refer to the parameterperson
instead ofTom
which is invalid
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
Happy coding!
Stone Preston
42,016 PointsI answered your other question concerning this challenge, but ill include it below for completeness in case someone else stumbles across this in the future
your code is similar for the code necessary for a different challenge. However the challenge you linked to is not that one. Did you get your code from another forum post perhaps? That code is for a tuples challenge, this challenge is on return types.
the challenge states Modify the definition of the function named greeting to return a String and replace the println statement with a return statement. The function should return a greeting. For example, if you pass in a string "Tom" then the return string would be: "Hello Tom".
the challenge initially has the following code:
func greeting(person: String) {
println("Hello \(person)")
}
it needs to return a string and you need to return the string, not print it
the swift eBook states:
You indicate the functionβs return type with the return arrow -> (a hyphen followed by a right angle bracket), which is followed by the name of the type to return.
func greeting(person: String) -> String {
return "Hello \(person)"
}
Jake N
612 Pointsthanks for the help guys
Stone Preston
42,016 PointsStone Preston
42,016 Pointshis code he posted is actually for the tuples challenge, however the challenge he is on that this question is linked to is for return types.