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

Richard Parkins IV
Richard Parkins IV
1,970 Points

I can't figure out why this is failing. let finalGreeting = "\(greeting) How are you?"

I have no idea why this is not working.

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

3 Answers

Angel Caro
Angel Caro
11,831 Points

You need to use string concatenation not interpolation, see below:

let finalGreeting = greeting + "How are you?" 

How do I show my code like that from the challenge?

The reason is because you are using an "Interpolated" string instead of a "Concatenated" string for the finalGreeting. you need to make the code look like this.

let name = "Carl"

let greeting = "Hi there, (name)." //Interpolated because it is using a value from another string.

let finalGreeting = greeting + "How are you?" //Concatenated because it is adding them together (Notice the "+").

Hope this helps!

Angel Caro
Angel Caro
11,831 Points

You show your code by using 3 backticks ` followed by the language you are using, the code on the line below and three backticks below the code.

Richard Parkins IV
Richard Parkins IV
1,970 Points

Thanks guys that fixed the problem. Sorry for the kinda stupid question lol

Angel Caro
Angel Caro
11,831 Points

There's no such thing as a stupid question, thats what where here for. Everyone is/was a beginner at some point.