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 Basics Swift Types String Manipulation

Jason Bateman
Jason Bateman
610 Points

I'm stuck on part 2. Concatenation. Tried everything

// Enter your code below let name = "jason bateman" let greeting = "Hi there, (name). How are you?" let finalGreeting = (greeting)

strings.swift
// Enter your code below
let name = "jason bateman"
let greeting = "Hi there, \(name). How are you?"
let finalGreeting = \(greeting)

2 Answers

Matthew Long
Matthew Long
28,407 Points

The biggest concern with your solution is don't forget quotations around the \() when using string interpolation.

I agree that this question is strange. In the real world I prefer string interpolation whenever possible. But the last challenge wants you to use string concatenation. You can still use some string interpolation so long as you have some concatenation in there. What I mean is both of the following pass:

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

However, the following does not pass. While, it is my preferred method, the challenge is checking that you know how to use string concatenation.

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

Hopefully that clears things up a little.

Jason Bateman
Jason Bateman
610 Points

Thanks, Mathew. As a beginner to code, never mind Swift it feels very easy to miss the small detail like quotations. Not long after I submitted the question I ended up with your third option which for me made sense as a beginner and I was already applauding myself for getting it right until I submitted. It became quite frustrating this task but I eventually passed it with a probable fluke. Thanks for replying to my question, hearing feedback (for the first time) from the community has given me a positive lift. I'll keep an eye on those quotations.