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 trialWilliam Hartvedt Skogstad
5,857 PointsI can't really understand what I should be doing here...
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".
func greeting(person: String) {
println("Hello \(person)")
}
2 Answers
William Li
Courses Plus Student 26,868 PointsHello, William Hartvedt Skogstad
Modify the definition of the function named greeting to return a String and replace the println statement with a return statement.
This challenge is asking for couple of things
- replace the println statement with return statement.
- since the println has been replaced with return, you should also set the proper return type for this function.
func greeting(person: String) -> String { // function now has return type String
return "Hello \(person)" // replaced println with return statement
}
Hope that helps.
Justin Horner
Treehouse Guest TeacherHello William,
To tell the function the type you want to return, you'll add the following to the method signature.
func greeting(person: String) -> String
Instead of calling println, you'll want to use the return keyword like so.
return "Hello \(person)"
I hope this helps.
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsFYI: The parentheses aren't required for the
return
statement, you can simply use the following.return "Hello \(person)"
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 Pointsoh right, changed the println to return but forgot to remove the parentheses. updated.