Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

strings.swift
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