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!
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 trial
Marlana Vassar463 Points
Hello, I'm doing the Swift Code Challenge and am trying to figure out where I'm going wrong in the editor.
This is the code I typed into Swift, it passed without errors (for the interpolated lesson):
let name = "Marlana" let greeting = "Hello" let interpolatedGGreeting = "(greeting), (name)."
However when I do the code challenge it marks this same set of code incorrect, when I make the suggested changes it's still incorrect. Just trying to figure out where I'm going wrong. I'd appreciate any insight you have on this issue!
// Enter your code below let name = "Marlana. " let greeting = "Hello" let interpolatedGGreeting = "\(greeting), \(name)"
Steven Deutsch21,046 Points
Hey Marlana Vassar,
You seem to understand the concept of String Interpolation, however, you're just not giving the output that the challenge is asking for. Your String currently reads as "Hello Marlana". It needs to read as, "Hi there, Marlana". You also have to use the variable names that the challenge asks you to, and not your own.
Take a look at my code below:
// Enter your code below let name = "Marlana. " let greeting = "Hi there, \(name)"
You don't need to use interpolation for the first part of the greeting. You can just use what is known as a string literal. Interpolation is a useful way to add information stored inside of variables/constants as part of a string.
Hope this helps! Good Luck!
Angel Caro11,831 Points
You need to use interpolation in the greeting constant like this:
let name = "Marlana" let greeting = "Hi there, (name)."
Marlana Vassar463 Points
I think I get it now, though I'm wondering why Swift marked both of them as ok. I want to learn to do it correctly and think that maybe I was overthinking the exercise and trying to do it exactly like the previous example. Once we fixed it I was able to do the second part of the challenge no problem. Thank you for explaining why I didn't need to use it, I think that's the thing I didn't really understand.