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 trialFergus Clare
12,120 PointsCorrect concatenation results in error
This code challenge includes the following request:
"Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?".
My code is as follows: let name = "Fergus" let greeting = "Hi there, (name)." let finalGreeting = "(greeting) How are you?"
Response from test after clicking "Check Work" is "Bummer! Make sure you are using concatenation..."
When I enter the same code in the Xcode IDE, I get the following value returned: "Hi there, Fergus. How are you?"
What am I doing wrong? This seems like a bug.
// Enter your code below
let name = "Fergus"
let greeting = "Hi there, \(name)."
let finalGreeting = "\(greeting) How are you?"
3 Answers
Tobias Helmrich
31,603 PointsHey Fergus,
your code is actually perfectly fine but the challenge wants you to concatenate the greeting
constant with the string " How are you?" but you're using string interpolation instead. To concatenate the constant with the string you have to separate them with a + like so:
// Enter your code below
let name = "Fergus"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + " How are you?"
I hope that helps! :)
Mikkel Rasmussen
31,772 Points// Enter your code below
let name = "Fergus"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + "How are you?"
Fergus Clare
12,120 PointsThank you Tobias. Your code solution worked and resolved my problem. I suggest to Treehouse that they more explicitly indicate the difference between the concatenation request vs. interpolation as the latter is what is being covered in this section of the coursework. Best.
John Steer-Fowler
Courses Plus Student 11,734 PointsJohn Steer-Fowler
Courses Plus Student 11,734 PointsHelpful answer +1 Tobias :D