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 trialCiaran Wood
Courses Plus Student 6,787 PointsString interpolation
When i do the activity after the string interpolation explanation I get it wrong in your box, but it works fine in xcode, what am I doing wrong? Heres the code
let name = "Caitríona"
let finalGreeting = "\("Hi there"), \(name). \("How are you?")"
3 Answers
Greg Kaleka
39,021 PointsHi Ciarian,
When doing string interpolation, you only need to interpolate things that aren't strings already, like constants, calculations, etc. You just need to remove some of your interpolation syntax:
let name = "Caitríona"
let finalGreeting = "Hi there, \(name). How are you?"
While the code you'd written does actually output the right string, this is the correct way to do it, since there's no need to string interpolate a string .
Ciaran Wood
Courses Plus Student 6,787 Pointsthanks, very helpful!
Anthia Tillbury
3,388 PointsThat's what I was doing as well.
The demo video didn't show that natural language could be used, it gave the impression that everything had to be entered as string interpolated (encased in brackets with a back slash).