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 trialJack Cummins
17,417 PointsWhat is the error?
I don't get interpolation and I put in many things that I thought would work but none worked. Can you find the error????????
// Enter your code below
let name = "Jack"
let greeting = "Hi There,"
let greeting = "(/greeting)" + "(/name)"
2 Answers
Shay Paustovsky
969 PointsHi Jack,
The syntax for "string interpolation" is as follows :
" /(variable) " from here I trust you can walk on your own. Hopefully I've helped ;)
Jaroslaw Adamowicz
11,634 PointsActually, this is not correct. You need to use the backslash ( \ ) to do it, not a forward slash ( / ) as you did in the example above. It should be:
"\(variable)"
Jaroslaw Adamowicz
11,634 PointsHello there,
Let's see:
For this line:
let greeting = "Hi There,"
you should use string interpolation (with name constant).
To use interpolation you need to use backslash() and then put name of constant or variable in parenthesis. Interpolation looks like this:
"This is some random string \(myString)"
NOTE: myString can be variable or constant, and don't even have to be string at all (it can be number for example).
Now you can apply this knowledge to come up with this:
let greeting = "Hi There, \(name)"
With this done you're almost there.
Note that you don't need interpolation in second part of the challenge, only simple concatenation (adding two strings with +).
I hope it helps!
Cheers!
Jarek
joe Bell Fenner
Courses Plus Student 2,646 Pointsjoe Bell Fenner
Courses Plus Student 2,646 Pointslet name = "Jack"
let greeting = "Hi there, (name)"