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 trialMichael Bates
13,344 PointsHow do I call a name within a function?
How do I call a name within a function? I am getting an error dealing with the name Tom, and I am not quite sure what is wrong.
func greeting(person: String) {
println("Hello")
}
greeting (Tom)
println("Hello (\(greeting)")
1 Answer
Steve Hunter
57,712 PointsHi Michael,
Try:
func greeting(person: String) {
println("Hello \(person)")
}
greeting("Tom")
So your func takes a String as a parameter. Strings are contained in double quotes. So, pass in Tom surrounded by double quotes. Inside the func, the output is then "Hello Tom" as we've used String interpolation to include the contents of the variable person
inside the string. Make sense?
I hope that helps,
Steve.
Michael Bates
13,344 PointsMichael Bates
13,344 PointsIndeed it does make sense now! Thank you for the help, Steve!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem; glad you got it sorted.