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 Basics Swift Types String Manipulation

Help with concatenation.

Need help better understanding concatenation, pretty sure I am not doing this one right!

strings.swift
// Enter your code below

let name = "TJ"

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

let finalGreeting = greeting + name + How are you?

1 Answer

Bowen Smith
Bowen Smith
15,223 Points

Hey, you've basically got it. When you're concatenating strings with the addition operator you can add constants or variables to strings of text, but new strings of text need quotes around them. So "How are you?" should have quotes around it. Another tricky part is remembering to put spaces between words when concatenating them with the addition operator. You can do this by adding a space in quotes (as shown below). In this example you also want to add some punctuation.

Also, the constant "greeting" already has the constant "name" in it because of the string interpolation. So if you were to print "finalGreeting" it would read "Hi there, TJTJHow are you?". So we can go ahead and leave "name" out of the "finalGreeting".

// Enter your code below

let name = "TJ"

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

let finalGreeting = greeting + ". " + "How are you?"

alternatively you could write

// Enter your code below

let name = "TJ"

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

let finalGreeting = greeting + ". How are you?"

thank you so much!