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 trialGeorge Gutieres
579 Pointsstring manipulation quiz need help
let name = "george" let greeting = "("Hi there,") (name)." this code is not working for string manipulation quiz can someone help
// Enter your code below
let name = "george"
let greeting = "\("Hi there,") \(name)."
2 Answers
Austin Whitelaw
9,065 PointsIf you look at your code, everything in the purple is recognized as a string. The part that says 'Hi there' is not in purple, and the reason for this is because of the quotation marks. When the compiler sees a quotation mark, everything after that is a string until the next quotation mark. So it literally sees the first part of that line as a string, then there's some random text in the middle, and then the last part is another string.
So basically you can get rid of the quotation marks around 'Hi there'. Also, you only need to put it inside the parentheses if it is variable/constant. So when you were trying to use the constant name, that was correct, but the first part just needed to be taken out of the parentheses. Sorry if my explanation is not well enough, but this should be pretty straight forward. Ask if you don't understand anything. It should look like this:
let greeting = "Hi there, \(name)."
See there is no need for any more quotation marks. Swift knows that once it sees the backslash in a string, something else is happening. Some other languages also do this but it may be in a different way.
anil rahman
7,786 Points// Enter your code below
let name = "Name" //i just put name
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + " How are you?" //concatenate greeting with the string
Kyle Lambert
1,969 PointsKyle Lambert
1,969 Points