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

michaelreyder
PLUS
michaelreyder
Courses Plus Student 10,067 Points

Swift 2.0 Basics/challenge 2 of 2

I'm getting an error that my "finalGreeting" constant value is incorrect. I've looked over my code and can't see anything wrong with it. If anyone has any idea why it's not working please let me know, as it will be greatly appreciated.

My code:

let name = "Michael"

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

let finalGreeting = greeting + " How are you?"

3 Answers

You need to omit the space before the "How are you?"

I know that's wrong, but it works.

Steve.

[EDIT: This has now been fixed - the space is OK]

can somebody explain why this code work? I don't get it.... I thought when making a string literal you always put "()" How is greeting just by itself? why are we using the + sign? my code is the following

let finalGreeting = "\(greeting) How are you?"

Hi Raymond,

You create a string literal just by using the quotes, like "Steve". Next, we're interpolating another string into an existing one using the \(var) technique. And lastly we're concatenating two strings using the + operator.

So, the final task requires that concatenation be used so you need to add the two strings together.

Steve.

Chris Jones
Chris Jones
4,521 Points

I also had a problem finishing this challenge. Delete the space before " How are you?" and it should pass. If it still doesn't pass try:

let finalGreeting = "(greeting)" + "How are you?"

this worked for me

let finalGreeting = greeting + "How are you?"