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

iOS

Alex Ferguson
Alex Ferguson
2,518 Points

Swift Functions Challenge 2 of 3

The question challenge says "Modify the println statement within the greeting function to use the variable person. For example, if you pass a person named "Tom" to the function then it should display: Hello Tom. (Hint: you must use string interpolation)."

func greeting() { var person = Tom println("Hello (person)") }

what am I doing wrong here

1 Answer

You're just missing the backslash before (person).

\(person) will work.

Also, you're missing your parameter in the function, though, maybe that's just on the forums.

Hope that helps.

Alex Ferguson
Alex Ferguson
2,518 Points

I did that, none of these work either:

func greeting(person: String) { println("Hello (person)") } greeting(Tom)

or

func greeting() { var person = "Tom" println("Hello (person)") }

or

func greeting() { var person: String = "Tom" println("Hello (person)") }

Oh jeez, I'm sorry, I missed another issue.

You're not supposed to assign a variable to "person", and you're not supposed to call the function. Just modify the println statement to include the variable "person".

Your first example, minus "greeting(Tom)" will work if you include the backslash before "(person)".

You can put your code on the forums so it's displayed correctly by following this detailed post: https://teamtreehouse.com/forum/posting-code-to-the-forum

In this case, use "swift" as the language.