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 trial

iOS Swift 2.0 Basics Swift Types String Interpolation

String 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
Seth Kroger
56,413 Points

This 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.

Fernando Angulo
Fernando Angulo
1,921 Points

Thank you Seth! I was stuck with this code challenge for a while. It was very helpful!

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

I 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!

Hi, 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
Anjali Pasupathy
28,883 Points

Oh, 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!

Thank you so much.

Thanks heaps Anjali. This clarified a lot for me too