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 trialNils Garland
18,416 PointsI dont understand
i dont understand how to concate
let name = "Pasan"
let greeting = "Hi there"
let interpolatedgreeting = "\(greeting), (name)"
let finalGreeting = "How are you?"
let greeting = "\(How are you?)"
let interpolatedgreeting = "\(finalGreeting), \(name). \(greeting)"
1 Answer
Jennifer Nordell
Treehouse TeacherConcatenating is simply taking two strings and smushing them together. We do this with a simple plus sign. Take this example:
let name = "Nils Garland"
let rocks = "rocks!"
let nilsGarlandRocks = name + " " + rocks
That code would assign the string "Nils Garland rocks!" to the variable nilsGarlandRocks. Note that I also used a concatenation to put an extra space in there. Otherwise the string would have been "Nils Garlandrocks!".
Interpolation is the use of the backslashes and parentheses. It tells the string "Hey! Insert the value of this variable here" So our example could have been written as:
let nilsGarlandRocks = "\(name) \(rocks)"
Hope that clarifies things a bit. But if you need the actual answer here's a link to where I've answered this particular one before. https://teamtreehouse.com/community/interpolatedaddress-challenge-task-2-of-2-question
I promise you're not alone in being confused by this! Happy coding!