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!

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 Manipulation

String Concatenate?

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?"

---What is string Concatenate and how can i complete this challenge?

let name = "Jesse"
let greeting = "hey there \(name)."

let finalGreeting = "\(greeting) How are you?"

3 Answers

Jessie, this code is 100% accurate as to what the challenge is prompting. Your mistake is simple and easily fixable, instead of:

let greeting = "hey there \(name)."

You will want:

let greeting = "Hi there \(name)."

If you have any further questions, feel free to ask!

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

You're using concatenation correctly. However, make sure that the content of the strings matches the instructions. It should say "Hi there", not "Hey there".

Kathleen Hang
Kathleen Hang
4,062 Points

I got stuck on that exercise and just completed it.

You also can't use \(greeting) because that is interpolation. Concatenation only deals with strings, not constants and variables.

The correct line for concatenation:

let finalGreeting = greeting +  "How are you?"

Hope this helps others that get stuck on this exercise in the future ! :D