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

What?

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

strings.swift
// Enter your code below

let name = "Seth Mitchell"
let finalGreeting = "How are you?"
let greeting = "Hi there, \(name) \(finalGreeting)"

I put my code in Xcode to see if it was correct and on my side it says its Good but on here it's saying it's not??

1 Answer

Alexandre Attar
Alexandre Attar
10,354 Points

Hi there, there's two small mistakes here. The first one is from the first part where its asks you to use string interpolation. It asks you first you name to the constant name which you did. And, then, it asks you to use String interpolation so your message looks like this "Hi there, Alex" ( I used my name there).

So in code this should look something like this:

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

For the second part it asks you to create a third constant named finalGreeting and use concatenation. For concatenating Strings we use '+' operator. Since, we already have the first part of the greeting "Hi there, Alex"; we can than simply add the ". How are you?" using string concatenation.

So for the second part it should look something like this:

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

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

Hope this helps!

Thank you so much! I am new to swift and I did not quite understand the wording that it was asking me!

Alexandre Attar
Alexandre Attar
10,354 Points

My pleasure! Don't hesitate to ask questions. And, Happy coding :)