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

Landon S
Landon S
3,433 Points

What am I doing wrong?

For the String Interpolation question I don't see what Im doing wrong here. If someone can explain to me what to fix so that this is correct that would be greatly appreciated.

This is for the String interpolation problem.

```{ // Enter your code below let name = "Bob" let greeting = "(Hi there,)(name)"

}

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

1 Answer

Hi Landon,

You're really close.

Let's look at a basic string example:

 let myString = "Hi there"

In the example above, there is no interpolation... it's just a basic string.

If you want to use string interpolation, you need to use the following syntax \() and place your variable within the parenthesis. Anything inside the parenthesis must be declared first.

So for example, if I want to use string interpolation on myString, I would write the following:

 let myString = "Hi there \(someOtherVariable)"

Notice in the example above, the 'Hi there' portion is not included inside the \() syntax. This is because 'Hi there' is not a variable... it's just a basic string. Notice, however, that someOtherVariable IS inside the \() syntax. This part of the string is being interpolated.

Now let's go back to your original answer:

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

Can you see where the mistake is? Your code isn't working because the program is looking for a variable called 'Hi there,' and it's not finding one.

To pass the challenge, you need to adjust it to the following:

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

Hope this helps!