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 Swift Functions and Optionals Functions Syntax and Parameters

Syntax and Parameters

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(person: String) { println("Hello " + person + ".") }

greeting("Tom")

What's wrong with my answer?

5 Answers

Hello Maher.

You are asked to use string interpolation here, not concatenation like you did.

So, after "println" you should use only one set of "", something like this:

("Hello (person)")

Also please note that the dot here is not requested in the string you want to print out

;)

Thanks Vittorio, but it turned out to another error: func greeting(person: String) { println("Hello (person)") } greeting(Tom)

You should NOT have the greeting function call in step 2.

Try deleting greeting("Tom")

got them all correct, Vittorio. thanks a lot for your enormous help

Sorry Maher, I got distracted while typing. The other thing that was needed is to add a backslash before the variable, to have it actually treated as a variable and not a string:

("Hello (person)")

Apologies for that.

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

Are you at step 3/3 ?

When you call the function, the word Tom has to go between "", like this:

greeting("Tom")

Also, I have noticed that I had put the backslash also in my previous answers but the site hides them.

Make sure you have a backslash right before (person).

This should be good then. Let me know

i am in step 2 Bummer! Your greeting printed "Hello Tom" when called with "XYZZY" as the parameter. It should have printed "Hello XYZZY".

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

Maher...this should work

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