Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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?"
Jennifer NordellTreehouse 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!