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 trialerikjosander
1,151 PointsWhy code not working? :(
let name = "Erik" let greeting = "("Hi there,") (name)"
// Enter your code below
let name = "Erik";
let greeting = "\("Hi there") \(name)"
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 PointsHey there!
In order for this to work, the code would have to be the following:
let name = "Erik";
let greeting = "Hi there, \(name)"
Only the dynamic part, in this case the variable name
, has to be wrapped in \()
.
All static text works just like a regular string, like:
let variable = "variable"
let anotherVariable = "another variable"
let text = "This is a static part. This prints out a \(variable) and \(anotherVariable). See?"
Make sure to have a look at Apple Docs: String Interpolation for a more in-depth explanation.
Hope that helps :)
erikjosander
1,151 Pointserikjosander
1,151 PointsThanks vary helpful!
Martin Wildfeuer
Courses Plus Student 11,071 PointsMartin Wildfeuer
Courses Plus Student 11,071 PointsYou are welcome :)