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 Manipulation

How do I concatenate the string literal.

I have tried to concatenate the string. Could you please tell me where I'm going wrong so I can fix it. And know better

strings.swift
// Enter your code below
let name = "Hussain"
let greeting = "Hi, there, + \(name) + \(finalGreeting)"

let finalGreeting = "How are you?"

4 Answers

You are very close! You don't need the "+" in your "greeting" string and you are also missing a period at the end of your string. For the finalGreeting, you should concatenate greeting with " How are you?". Try this code snippet instead:

// Enter your code below

let name = "Hussain"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + " How are you?"

Thank you both for your replies :). They helped a lot

I was stuck on this one for while when I first started too.

Just keep in mind that concatenate means to add together

let string1 = "hello"
let string2 = " there"
var welcome = string1 + string2
let name = "Aaron"
let greeting = "Hi there \(name)."
let finalGreeting = "\(greeting)" + "How are you?"

Thanks a-lot

Thanks a-lot

Hello Aaron Ackerman, for the finalGreeting variable, it isn't necessary to use "(greeting)". You could use use "greeting". Example:

// Instead of this, 
let finalGreeting = "\(greeting)" + "How are you?"

// Do this:
let finalGreeting = greeting + "How are you?"
anil rahman
anil rahman
7,786 Points
// Enter your code below
let name = "Hussain"

//task 1 says just add name 
let greeting = "Hi, there, + \(name)."

//task 2 says take greeting constant and add to the end 
let finalGreeting = greeting + "How are you?"