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 trial
AJ S
Courses Plus Student 559 PointsI can't pass this task, I don't understand what I'm doing wrong.
It says "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 a string "Tom" then the return string would be: "Hello Tom".
This task is found in the iOS Development with Swift-Swift Functions & Optionals- Function Return Types
AJ S
Courses Plus Student 559 Pointsfunc greeting(person: String) -> String { return person } let person = "Tom" println("Hello (greeting(person))")
AJ S
Courses Plus Student 559 PointsThis is how you start off with func greeting(person: String) { println("Hello (person)") }
and the other comment is what I have done so far
3 Answers
Damien Watson
27,419 PointsMaybe something like?
func greeting(person: String) -> String {
return ("Hello \(person)")
}
var hello = greeting("Tom")
Victor Rundbaken
14,037 PointsI'm not very familiar with swift but I think you just need to add a backslash
println("Hello \(greeting(person))")
AJ S
Courses Plus Student 559 PointsI was been stuck on this question for a long time, thanks a lot Victor, appreciate it!
Victor Rundbaken
14,037 PointsVictor Rundbaken
14,037 PointsCan you copy and paste the code it gives you and what you have so far?