Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Basics Swift Types String Manipulation

Marlana Vassar
Marlana Vassar
463 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!

Thank you,

Sincerely,

Marlana

strings.swift
// Enter your code below
let name = "Marlana. "
let greeting = "Hello"
let interpolatedGGreeting = "\(greeting), \(name)"

3 Answers

Steven Deutsch
Steven Deutsch
21,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 Caro
Angel Caro
11,831 Points

You need to use interpolation in the greeting constant like this:

let name = "Marlana" let greeting = "Hi there, (name)."

Marlana Vassar
Marlana Vassar
463 Points

Thank you for your help Angel!

Angel Caro
Angel Caro
11,831 Points

No problem i was having trouble getting the code to display right using an iPad thats why it was all on on line.

Marlana Vassar
Marlana Vassar
463 Points

Hey 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
Steven Deutsch
21,046 Points

Hey 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.