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 trialWardah M
477 PointsString interpolation confusion
I'm having trouble with the question "Now that we have an appropriate greeting for our user, let's make a bit more polite by concatenating the greeting string with a second string literal.
Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?".
Example: "Hi there, Pasan. How are you?"
This is how I did my code and it is not working: let name = "Wardah" let name = "finalGreeting"
let greeting = "Hi there, (name)." let finalGreeting = "How are you?"
It would be great if someone can help me.
5 Answers
Seth Kroger
56,413 PointsThis challenge step gets a lot of people because it's picky about you concatenating the two strings instead of interpolating: let finalGreeting = greeting + " How are you?"
It's the same result, but with a different method.
Anjali Pasupathy
28,883 PointsI think this is the code you want:
let name = "Wardah" // this line was correct
// Don't redeclare name with the String "finalGreeting"
// The next line inserts name ("Wardah") into the String to get "Hi there, Wardah."
let greeting = "Hi there, \(name)."
// The next line inserts greeting ("Hi there, Wardah.") into the String to get "Hi there, Wardah. How are you?"
let finalGreeting = "\(greeting) How are you?"
I hope this helps!
Wardah M
477 PointsHi, So I tried doing this but it still won't work. Please help:
let name = "Wardah"
let greeting = "Hi there, "
let finalGreeting = "(greeting) How are you?"
Anjali Pasupathy
28,883 PointsOh, this is for the challenge! I thought this was some confusion over something in the video. It feels like a long time since I've thought about this particular challenge.
But what Seth said is correct. The challenge asks you to make greeting an interpolated String, and make finalGreeting a concatenated String. Thus, when instantiating greeting, you should use String interpolation. When instantiating finalGreeting, you should use String concatenation.
// STRING INTERPOLATION
let greeting = "Hi there, \(name)."
// STRING CONCATENATION
let finalGreeting = greeting + " How are you?"
I'm sorry for the confusion, and I hope this helps!
Wardah M
477 PointsThank you so much.
Anjali Pasupathy
28,883 PointsYou're welcome!
nada sironic
1,249 PointsThanks heaps Anjali. This clarified a lot for me too
Fernando Angulo
1,921 PointsFernando Angulo
1,921 PointsThank you Seth! I was stuck with this code challenge for a while. It was very helpful!