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

Anthony Babich
Anthony Babich
5,505 Points

I decided not to ask this question but I do need to mention something.

Actually I am completely 100% certain why this does not work. At least, I think. I think that because of the way TeamTreeHouse validates their code, I am wrong inevitably.

I am hoping someone can give me a valid explanation why my initial response to the question is wrong. If it differs from my original assumption.

Firstly we create a constant named Name. Secondly we use string interpolation to include the use of "name" variable inside of our "greeting" variable. Okay so here is where I don't understand why it doesn't work.

The question is asking me to declare a constant named finalGreeting and to concatenate the use of "greeting" constant.

So I use...

let finalGreeting = "\(greeting). How are you?"

That doesn't work.

And, I guess, I'm not concatenating.

Is that the only problem????????

I can't be the only person that has had issues with this.

So...

let name = "Anthony Babich"
let greeting = "\(name)"
let finalGreeting = "\(greeting) " + "How are you?"

The last set of code works and I am following the rules of concatenating the strings but it says nothing about string interpolation and I still don't understand why my first answer wasn't correct again outside of answering with concatenation.

strings.swift
// Enter your code below

1 Answer

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

Yes, because the challenge is specifically testing your ability to achieve similar results using different methods. If it asks for concatenation, it definitely is testing for that. Here's a link where you can see no less than 7 pages of answers to this code challenge and I'm guessing about 90% of them are because people only used interpolation instead of concatenation.

https://teamtreehouse.com/community/code-challenge:9402

Challenges are very picky and they are looking for very specific things. I've seen people fail code challenges simply because of the capitalization in a string they want returned. I've seen code that fails because the number was printed instead of returned or vice versa. But try to remember also, that it's not a real live person evaluating your code... it's another piece of code.

Treehouse is not the only programming site that has these demands on the code you input. The same can be said for Free Code Camp and Codecademy. Links provided:

https://www.freecodecamp.com/

https://www.codecademy.com/learn

Anthony Babich
Anthony Babich
5,505 Points

I see, thank you Jennifer! This is exactly what I was looking for. Honestly I'm not that confused I just really want confirmation that I am not wrong. I really appreciate it thank you.

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

Anthony Babich You're doing fine! Hang in there :) I find that if I can't get a challenge to pass after several tries, the most important thing is to re-read the instructions. Sometimes I have to stop myself and say: "Ok I thought I know what they asked for, but what did they actually ask for?" Very rarely are what I thought they wanted and what they really wanted the same thing.