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 trialJesse Lopez
1,870 PointsSwift Functions help!
What is wrong with my code?
func greeting(person: String) -> {
return ("Hello \("Tom") ")
}
greetin("tom")
2 Answers
Dave Berning
17,365 PointsYou're close Jesse. Make sure you state the return type as "String", change "println" to "return", and remove the parenthesis around your return value. You also don't need to create an instance of greeting for this code challenge.
func greeting(person: String) -> String {
return "Hello \(person)"
}
Dan Oswalt
23,438 PointsAfter the -> arrow, define the data type of the return, which is String.
Also, your call says greetin, you're missing the g on the end.
Jesse Lopez
1,870 PointsJesse Lopez
1,870 PointsThank you so much! i actually successfully completed this challenge a while ago. But, i still don't understand it.
(person: String)
return "Hello (person)" ---------- What exactly does 'person' return?
Dave Berning
17,365 PointsDave Berning
17,365 PointsJesse Lopez, "person" is an argument that the "func greeting" accepts. If you create an instance of greeting somewhere in your code, one of the things that you have to do is provide a string; this can be any string (that's where (person: String) -> String comes in).
When I create the instance with a variable (or constant) I'm assigning it to the "greeting" function". The string in the parenthesis of the variable which is sent to the greeting function and returns, "Hello Dave". It's helpful if you want to reference that function later in your code somewhere else. So instead of typing. "Hello Dave" over and over again, I can just call the variable "name" or even reassign it later.