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 trialWei Luo
1,372 PointsTask1
I would like to know why my code didn't work?
func greeting(person: String) {
println("Hello \(person)")
}
2 Answers
tobiaskrause
9,160 PointsYou are still printing the greeting...but the challange said you should use the return statement
func greeting(person: String) -> String{
return "Hello \(person)"
}
Some information https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html
Wei Luo
1,372 PointsWhatΒ if I chant it to return person } println("Hello (greeting(person))")
tobiaskrause
9,160 PointsUhm i dont really get that question...I already posted the right code. The problem is, that you DONT have to PRINT anything.
also you need to add the "-> String" which is the return-type of your function.
return is not the same as println Compare my code and yours and you should see the differences. Also take a look at my link it should help you
Wei Luo
1,372 PointsThanks a lot Tobias Krause!
chrisverra
3,760 Pointschrisverra
3,760 Pointsi think you forgot the return type something like
func greeting(person: String) -> String { println("Hello (person)") }