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
kurt broughton
553 PointsStuck on passing parameter to a function
The challenge asked me to pass the parameter to the function and I can't figure out what I'm doing wrong. My code:
func greeting(person: String){
println("Hello \(person)")}
greeting("Tom")
The error reads: Your 'greeting' printed "Hello Tom" when called with "XYXXY" as the parameter. It should have printed "Hello XYZZY".
It seems to be saying my code did what was intended but is somehow wrong. Any thoughts? The parenthesis are white, Hello is green, \ is red and person is blue
1 Answer
Ben Griffith
5,808 PointsIn order for string interpolation to work you need to have a \ before your parenthesis. So the correct code is;
println("Hello \(person)")
kurt broughton
553 Pointskurt broughton
553 PointsThank you but the interpolation syntax is correct. I can't seem to get the post to show it though.
Ben Griffith
5,808 PointsBen Griffith
5,808 PointsThis is strange! Is this the task you're on? Part 3 of 3
http://teamtreehouse.com/library/functions-and-optionals/functions/syntax-and-parameters
I've tried your code and added the \ and it's accepted it on mine.
PS. If you want to write code on here, have a new line at the start and end of your code with ```
kurt broughton
553 Pointskurt broughton
553 PointsThat is weird. I tried it again without re writing anything and on the third try it worked. It must have been some sort of bug or Loki the trickster having fun at my expense again. Thanks for your help though, I was wondering how to make the code show up like you did. Cheers!
Unless it didn't update to show that challenge as complete so now I need it to move on and the code is not working again... Still being vexed by some sort of gremlin.