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

Confused on how to "concatenate the value of greeting with the string literal " How are you?"."

Not sure how to concatenate this or what that means exactly. Do I need to add a normal constant to an interpolation ?

OR is there a place to see the answers to see my mistake?

my code is.

let name = "Chris." let hi = "Hi there," let finalGreeting = "How are you?" let greeting = "(hi) (name) (finalGreeting)"

strings.swift
let name = "Chris."
let hi = "Hi there,"
let finalGreeting = "How are you?"
let greeting = "\(hi) \(name) \(finalGreeting)"

1 Answer

Matthew Long
Matthew Long
28,407 Points

First, I'm not entirely sure how you passed the first part of the challenge unless you changed your code since passing. Maybe it's not as picky with variable names as I thought. The first challenge is asking you to create a constant named name, and then a constant named greeting. It didn't ask for a constant named hi. Lastly, it want's you to use string interpolation to interpolate the name in the greeting constant. This you basically have.

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

Keep in mind that changing the greeting constant in part two of the challenge will make part one no longer pass.

Part two of the challenge wants you to use string concatenation. While, in my opinion it is most often better to use string interpolation, this challenge requires string concatenation. String concatenation means to add two or more strings together to create a new string using the + operator. To accomplish this simply add ". How are you?" to greeting and assign that to afinalGreeting` constant:

let finalGreeting = greeting + ". How are you?"

There are a few other ways you could solve part two, but you must use string concatenation. Hopefully this clears up string concatenation for you. Happy coding! :smile: