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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![jurgen meco](https://uploads.teamtreehouse.com/production/profile-photos/2986252/micro_IMG_0561.jpg)
jurgen meco
30 PointsWhat do i hav eto do on, "Call the function greeting and pass it the string "Tom".?
i want it to understanding this line of code for this community to help me please because i wan to go to other parts of the course I'm taking.
func greeting(name: "Tom") {
println("Hello \(greeting)")
}
1 Answer
![Jennifer Nordell](https://uploads.teamtreehouse.com/production/profile-photos/5432702/micro_jen-square.jpg)
Jennifer Nordell
Treehouse TeacherHi there! Keep in mind that most challenges will require that you build upon the code that you already had. So the parameter you're accepting shouldn't have changed. It should be named person
and of type String
. So let's take a look:
func greeting(person: String) {
println("Hello \(person)")
}
greeting("Tom")
Here we have a function named greeting
. It's going to accept one piece of data being sent to it by another piece of code. When that data gets there it is of type String
and its name is person
. It now works just like any other variable. We can now print out a line with with "Hello" and then whatever was sent into person
. Now outside of the function we call it. And we do this simply by stating the name of the function and then putting what we want to pass inside the parentheses. So we call greeting
and then send in "Tom". This is equivalent to saying person = "Tom"
. The function will then print a line with "Hello Tom". Hope this clarifies things!