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 trialjohannestoikka
335 PointsWhat could possibly be wrong with this line of code?!?!?!?!?!?!?!?!?
,
let name = "Johannes"
let greeting = "Hi there \(name)"
let finalGreeting = "\(greeting) How are you?"
3 Answers
Rich Donnellan
Treehouse Moderator 27,696 PointsThat last line of code.
Use concatenation to combine the greeting
string with a second string literal.
Example:
variable + " This is a string of text!"
noreenqureshipowley
iOS Development Techdegree Student 1,096 PointsHi there,
Looking at your code I wanted to answer a question I had myself - can you or can you not interpolate an already interpolated string. The answer is yes, you can. I experimented writing some of my own code but yours as well. I think the editor was looking for the concatenation of your answer as Rich had mentioned, which is why it didn't accept. I hope this helps.
//My Experiment
var interpolateOnce = "Get this string,"
print(interpolateOnce)
var interpolateTwice = "\(interpolateOnce) and this one too,"
print(interpolateTwice)
var interpolateThrice = "\(interpolateTwice) and this second to last one,"
print(interpolateThrice)
var interpolateFourTimes = "\(interpolateThrice) and this final one"
print(interpolateFourTimes)
//Your Example
let name = "Johannes"
print(name)
let greeting = "Hi there \(name)"
print(greeting)
let finalGreeting = "\(greeting) How are you?"
print(finalGreeting)
johannestoikka
335 Pointsok i found out the problem im good
Rich Donnellan
Treehouse Moderator 27,696 PointsThat's great!
Were either of the answers helpful? Was it a completely different issue? It would help others if you could elaborate on what you found or mark the appropriate answer best.