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 trialMarlana Vassar
463 PointsHello, 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!
Thank you,
Sincerely,
Marlana
// Enter your code below
let name = "Marlana. "
let greeting = "Hello"
let interpolatedGGreeting = "\(greeting), \(name)"
3 Answers
Steven Deutsch
21,046 PointsHey 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 Caro
11,831 PointsYou need to use interpolation in the greeting constant like this:
let name = "Marlana" let greeting = "Hi there, (name)."
Marlana Vassar
463 PointsThank you for your help Angel!
Angel Caro
11,831 PointsNo problem i was having trouble getting the code to display right using an iPad thats why it was all on on line.
Marlana Vassar
463 PointsHey Steven,
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.
Steven Deutsch
21,046 PointsHey Marlana,
You're asking why you did not receive errors when writing your original code in Xcode? Your first solution was completely valid Swift code, it just was not what the challenge instructions were asking of you. Your compiler only triggers errors for invalid code.