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

Cannot figure out what makes this string invalid

Greeting is supposed to be an interpolated string that incorporates the following:

  • "Hi there, "
  • Constant named name
  • "."

Any assistance would be much appreciated

strings.swift
// Enter your code below

let name = "Clay Walter"

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

1 Answer

Tobias Mahnert
Tobias Mahnert
89,414 Points

You're very close. Check the answer below and if you have any further questions let me know

let name = "Clay Walter"

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

Thanks so much!

MIchael Montoya
MIchael Montoya
3,222 Points

Can you explain why the first answer was incorrect?

Tobias Mahnert
Tobias Mahnert
89,414 Points

He uses the wrong syntax which throws an Error. If you want to incorporate strings which are declared to constants or variables incorporate into other strings, you have to use the syntax like in the example above. You can also declare hi there to a separate variable and incorporate two variables to pass the challenge. I'm sure there are also other ways to do it but sometimes the challenge only concentrates on one particular way to solve it. Below you have an example how to do it with two variables

let name = "Cley Walter"
let extend = "Hi there"

let greeting =  "\(extend), \(name)."