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

need help..

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

my code. let name = " Veasna Mam" let greeting = "Hi there, (name)." let finalGreeting = greeting + "Hi there, Linda. How are you?

strings.swift
// Enter your code below
let name = " Veasna Mam"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + "Hi there, Linda. How are you?

4 Answers

Andrew Boryk
Andrew Boryk
15,916 Points

What you did with this part:

// Enter your code below  
let name = " Veasna Mam"  
let greeting = "Hi there, \(name)."  

Is that you created two strings, creating the greeting variable by using string interpolation with the name variable (the '(name)' part)

Now, you want to apply the same concept when creating the finalGreeting variable. Just for one point before I go on, I noticed that you didn't close out your string quotation marks. I don't know if this was because of a copy pasting issue or what not, but just always be aware of that when writing code and also asking questions (because then it could lead to someone brushing off your question by saying you missed a quotation and not reading the rest of your code).

Anyway, the approach you should take is with String Interpolation again, as follows:

let finalGreeting = "\(greeting) How are you?"
Russell Atkins
Russell Atkins
3,921 Points

This still does not pass in the code challenge for me.

let name = "Russell Atkins" let greeting = "Hi There, (name)." let finalGreeting = "(greeting) How are you?"

Russell Atkins
Russell Atkins
3,921 Points

Never mind I figured it out - it needs to be greeting + "How are you?"

Andrew Boryk
Andrew Boryk
15,916 Points

Yes, it can be done that way. Or it could also be done let finalGreeting = "(greeting) How are you?"

You were missing the "\" before the (greeting) and (name)