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 triallarry bland
Courses Plus Student 7,846 Pointsok i thought i had it
is my code off
// Enter your code below
let name = "Larry"
let greeting = "Hi there, + \(name)."
let finalGreeting = "\(greeting) + How are you?"
3 Answers
Ollie King
10,194 PointsHi Larry,
As you are using string interpolation, you don't need to add the binding operator (+). Try removing the '+' in your code and this should solve the problem :)
larry bland
Courses Plus Student 7,846 Pointsinteresting but the code challenge suggests that i am not using interpolation
Ollie King
10,194 PointsAh ok, in that situation as when concatenating a string then the code would look like this:
// Enter your code below
let name = "Larry" let greeting = "Hi there, (name)." // Interpolation
let finalGreeting = greeting + "How are you?" // Concatenation
the backslash and parenthesis only apply in interpolation.
So reviewing your code above you were really close!
Your second line of code didn't require the binary operator between "Hi there, " and (name) Then your third line of code didn't need the backslash and parenthesis and only "double quotes" around "How are you?"
Does this help? Or have I just confused you further..? Haha! :)
larry bland
Courses Plus Student 7,846 Pointslol a little so with interpolation once the variable is declared with interpolation there is no need to redeclare with the ()
Ollie King
10,194 PointsHaha no problem. I'll try my best to explain.
It depends if you are going to use interpolation or concatenation in the new variable/constant. Basically all your doing is creating variables/constants and using them together in a string.
If you were to do this solely using interpolation then the variables/constants you are referencing go into () as you are directly pulling them into you "String of text", otherwise it would all read as a string rather than a string with added values (e.g. "Hi there, (name)" without the () would literally print "Hi there, name" rather than the desired "Hi there, Larry").
If you were to do this solely using concatenation then the referenced variables/constants don't require anything but you need to add the binary operator. You're essentially saying grab greeting /which is already holding data "Hi there, (name)"/. and add(+) "How are you?" - How are you has to be in double quotes as this is a string.
larry bland
Courses Plus Student 7,846 Pointslarry bland
Courses Plus Student 7,846 Pointsthank you testing the code now