iOS Swift Basics Swift Types String Manipulation

David Moore
David Moore
108 Points

Cannot Complete the Concatenation Example

Trying to complete task 2 in the concatenation section. Code is attached.

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

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Staff

Hi there, David Moore ! It looks like you're doing great and you were off to a great start. In fact, there are only two characters here stopping you from passing the second step. You have put quotation marks around "greeting" which means that it's no longer the variable greeting. It's literally the word greeting. At this point the value stored in finalGreeting is greeting How are you? instead of Hi there, David. How are you?

You wrote:

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

But you meant to write:

// note the removal of the quotation marks from greeting
let finalGreeting =  greeting + " " + "How are you?"

Now, that being said, you could even shorten that just a bit and instead put the space inside the last string like this:

let finalGreeting =  greeting + " How are you?"

Hope this helps! :sparkles: