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 trial

iOS Swift 2.0 Basics Swift Types String Manipulation

Alli Semans
Alli Semans
723 Points

Do not understand why work is not right

I typed my answer into XCode and it said it was correct by saying, "Hi there, Alli." I copied and pasted it into Team treehouse and it said it was incorrect. I am unsure how to fix this to resolve the problem.

strings.swift
let name = "Alli"
let greeting = "Hi there,"
let interpolatedGreeting = "\(greeting),\(name)"

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! There's a few problems here. Yes, your code works, but it doesn't exactly match the requirements of the challenge. First, you seem to have changed your greeting constant from what passed in the first step. Secondly, the last constant is supposed to be named finalGreeting not interpolatedGreeting. Third, the challenge explicitly asks you to use concatenation on the final step. But you've used string interpolation.

Remember, concatenation is combining two or more strings with a plus sign. Interpolation is the use of backslashes and parentheses to insert the value of the variable into that spot.

Take a look:

let name = "Alli"
let greeting = "Hi there, \(name)."
let finalGreeting = greeting + " How are you?"

Hope this helps! :sparkles:

Xavier Fricker
Xavier Fricker
173 Points

Same problem as Alli. There is an issue with this second challenge. Nowhere is mentioned that it needs to be a concatenation, on the contrary it only says that it has to be an interpolation.

Should be fixed by the Team Treehouse Team!

Xavier Fricker
Xavier Fricker
173 Points

The issue is at the second step.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Xavier Fricker!

This is a direct quote from the first step.

Second, declare a constant named greeting. Set the value of greeting to an interpolated string that combines "Hi there, " with the string stored in the name constant.

Note that they explicitly say that the value in the greeting variable needs to contain an interpolated string.

This is a direct quote from the second step.

Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?".

Here, they explictly say to "contatenate the value" and store it in finalGreeting.

And here is a direct quote from you:

Nowhere is mentioned that it needs to be a concatenation, on the contrary it only says that it has to be an interpolation.

This is simply not accurate.

Happy coding! :sparkles:

Xavier Fricker
Xavier Fricker
173 Points

"Note that they explicitly say that the value in the greeting variable needs to contain an interpolated string."

Yes, and that is the part that was not working. I did exactly that' just like you showed explained and it didn't work.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I really don't know what to tell you. If I copy/paste the code I wrote above in the challenge, it passes both steps. Try restarting the challenge and copy/paste my code in there.