Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

lordcozycat
lordcozycat
11,940 Points

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)") }

lordcozycat
lordcozycat
11,940 Points

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.