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 trialMaher Alhasan
974 PointsSyntax 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
Vittorio Somaschini
33,371 PointsHello 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
;)
Vittorio Somaschini
33,371 PointsYou should NOT have the greeting function call in step 2.
Try deleting greeting("Tom")
Maher Alhasan
974 Pointsgot them all correct, Vittorio. thanks a lot for your enormous help
Vittorio Somaschini
33,371 PointsSorry 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.
Maher Alhasan
974 Pointsthanx still wrong func greeting(person: String) { println("Hello (person)") } greeting(Tom)
Vittorio Somaschini
33,371 PointsAre 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
Maher Alhasan
974 Pointsi 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")
Yonesh Suwal
764 PointsMaher...this should work
func greeting(person:String) { println("Hello (person)") }
Maher Alhasan
974 PointsMaher Alhasan
974 PointsThanks Vittorio, but it turned out to another error: func greeting(person: String) { println("Hello (person)") } greeting(Tom)