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

Asad Chishty
Asad Chishty
422 Points

I've typed out exactly what's specified but its coming up wrong. What's my mistake here?

I'm following the instructions exactly but I keep getting an error. What's the mistake here?

strings.swift
let name = "Asad"

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

let finalGreeting = " How are you?"

let concatenation = "greeting" + "finalGreeting"

3 Answers

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

Hi there! You're close here, but it doesn't exactly meet the specifications. So I'm going to give some hints because you are so close.

  • This should only be three lines of code
  • greeting needs to have a full stop/period at the end as indicated by the instructions in step 1
  • finalGreeting should use concatenation of the variable greeting along with the string literal you currently have
  • the constant concatenation is neither needed nor asked for by the challenge specifications

I think you can get it done with these hints, but let me know if you're still stuck! :sparkles:

Asad Chishty
Asad Chishty
422 Points

Hi Jennifer,

I'm still not able to do it, I tried concatenation with each possible entry and it won't work.

I can't post a screen shot but the code I have is below.

let name = "Asad"

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

let finalGreeting = "greeting + name"

Isn't the last line using concatenation of the variable greeting and the string literal for my name?

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

It's still not quite correct. First, you've removed the backslash in your string interpolation in the greeting constant. But you did add the full stop! And the finalGreeting constant is supposed to concatenate the variables greeting and the string literal " How are you?". Note the leading space before the word "How". But what you've done is assign a string literal of "greeting + name" to the `finalGreeting. Take a look:

// Enter your code below
let name = "Asad"

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

let finalGreeting = greeting + " How are you?"

Here we set the name to the string literal "Asad". Then in greeting we assign the string "Hi there, \(name)". Because of the string interpolation here, greeting will now hold the string "Hi there, Asad.". Then we create finalGreeting and concatenate the string in in greeting (as described in the previous sentence) and the string literal " How are you?". The end result will be that finalGreeting will hold the string "Hi there, Asad. How are you?". Hope this clarifies things! :sparkles:

Asad Chishty
Asad Chishty
422 Points

I got it!

It was

let finalGreeting = greeting + " How are you?"

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

Good job! I was posting when you were posting yours :smiley: But I'll leave my comment up for a breakdown for other students who might be looking for this answer.

Asad Chishty
Asad Chishty
422 Points

Thanks so much, Jennifer!

I really appreciate your help :D