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.
Valeria Ruiz948 Points
concatenation mistake or bug?
I am doing Swift 2.0 Basics and I am learning about concatenation. I have tried everything I have learned so far for this method and still I can't get it right. The error message I get ays to make sure I am using concatenation, which I am.
Could someone please help me in finding out how I could concatenate better? My code is below
// Enter your code below let name = "Valeria" let hi = "Hi" let there = "there" let greeting = "\(hi) \(there), \(name)." let stringLiteral = "How are you?" let finalGreeting = "\(greeting) \(stringLiteral)"
Concatention is adding the strings together using the plus sign. What you've done there is interpolation.
finalGreeting should be made up of
greeting + " How are you".
Something like this should get you through the challenge:
// Enter your code below let name = "Steve" let greeting = "Hi there, \(name)" let finalGreeting = greeting + " How are you?"
You start with
name holding your name, then interpolate that into the
greeting constant. Next, you concatenate
greeting with the additional string " How are you?" by adding them together using the + operator.
I hope that helps,