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 trialstr
3,149 PointsHow do I go about making sure a constant has an interpolated string value?
I don't understand how to go about assigning the constant (in this case "greeting") to the interpolated string. I declared the the constant "greeting" and gave it a string value of "Hi there" but I can't seem to figure out how to use the interpolated sting method to display the values from "name" and "greeting" constants.
// Enter your code below
let name = "bob."
let greeting = "Hi there"
let interpolatedGreeting = "\(greeting), \(name)"
2 Answers
jcorum
71,830 PointsTask 1:
let name = "bob"
let greeting = "Hi there, \(name)."
They didn't want you to create a third constant. They just wanted you to interpolate name into greeting. Also, the editor is very picky, so you have to put the period in the right place. Not in name, but at the end of the String in greeting.
For Task 2 you will add:
let finalGreeting = "Hi there, " + name + ". How are you?"
So, at the end, you have an example of String interpolation and an example of String concatenation.
Angel Caro
11,831 PointsYou have to do the string interpolation in the greeting constant:
let name = "bob"
let greeting = "Hi there, \(name)."
str
3,149 Pointsstr
3,149 PointsThank you for your help! I know understand it.