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 trialAsh Preston
1,013 PointsSwift 2.0 interpolatedGreeting task. Code not accepted and I can't see the issue.
What's wrong with this code below? The output on Xcode is as expected, but the compiler in the tutorial code input says the value isn't correct for an interpolated string? Any ideas?
let name = "Ash"
let greeting = "("Hi there,") (name)"
// Enter your code below
let name = "Ash"
let greeting = "\("Hi there,") \(name)"
2 Answers
Becky Steele
16,229 PointsHi Ash!
Thanks for asking! The person above is correct, but allow me to elaborate.
let name = "Ash"
This ^^^ is the right way to declare a constant name
and assign it the string "Ash" so good job there!
If you want to use name
, you'll have to use string interpolation for that. Anytime you have a constant or variable that you want to output to the user, you represent it like this: \(name)
.
Your correct string interpolation would be:
let greeting = "Hi there, \(name)."
Hope that helps! Keep at it!
jcorum
71,830 PointsSeveral problems. First, you don't include Strings within Strings. Second, the editor is picky. It said it wanted a final period. So with these changes:
let name = "Ash"
let greeting = "Hi there, \(name)."
Ash Preston
1,013 PointsThank you so moocher your help, this has really cleared this up and set me straight moving forwards learning Swift!
Ash Preston
1,013 PointsAsh Preston
1,013 PointsThanks to you too for the brilliant explanation. I'm completely new to coding so setting things straight like this is really helpful to me. Cheers!