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

Code works in Xcode but doesn't pass challenge

I'm having trouble with the second part of this challenge. I'm able to get my code to pass the first task here with the name and greeting constants, but the challenge is tripping me up on my finalGreeting.

I'm supposed to doing this: Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?".

It looks like my finalGreeting is outputting as expected in Xcode but for some reason the challenge doesn't like it. What am I missing?

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

i did it like you, but i think there is a treehouse software system problem, isn't it?

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

This is what you're missing. It's one line in the instructions on step 2. "Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?"."

You're not using concatenation. Treehouse is checking to see that you understand both interpolation and concatenation.

The line you need is:

let finalGreeting = greeting + "How are you?"

Remember interpolation is the backslash and parentheses that tells Swift where to insert the value of a variable in that spot. Concatenation is simply a plus sign which takes two strings and puts them together. Hope this helps!

Thanks Jennifer, this is perfect. I needed to pay more attention and see that the challenge was trying to make sure I knew multiple ways to get a similar result.