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 trialmichaelreyder
Courses Plus Student 10,067 PointsSwift 2.0 Basics/challenge 2 of 2
I'm getting an error that my "finalGreeting" constant value is incorrect. I've looked over my code and can't see anything wrong with it. If anyone has any idea why it's not working please let me know, as it will be greatly appreciated.
My code:
let name = "Michael"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + " How are you?"
3 Answers
Steve Hunter
57,712 PointsYou need to omit the space before the "How are you?"
I know that's wrong, but it works.
Steve.
[EDIT: This has now been fixed - the space is OK]
Chris Jones
4,521 PointsI also had a problem finishing this challenge. Delete the space before " How are you?" and it should pass. If it still doesn't pass try:
let finalGreeting = "(greeting)" + "How are you?"
Robert Brown
12,269 Pointsthis worked for me
let finalGreeting = greeting + "How are you?"
Raymond Carter, Jr.
iOS Development Techdegree Student 488 PointsRaymond Carter, Jr.
iOS Development Techdegree Student 488 Pointscan somebody explain why this code work? I don't get it.... I thought when making a string literal you always put "()" How is greeting just by itself? why are we using the + sign? my code is the following
let finalGreeting = "\(greeting) How are you?"
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHi Raymond,
You create a string literal just by using the quotes, like
"Steve"
. Next, we're interpolating another string into an existing one using the\(var)
technique. And lastly we're concatenating two strings using the+
operator.So, the final task requires that concatenation be used so you need to add the two strings together.
Steve.