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

stephenallison
stephenallison
8,559 Points

Swift 2.0 Basics - Challange Task 2 of 2 Trouble with my concatenation

Below is a copy of my code. Im receiving an error that my concatenation is not correct. Not sure what I'm doing wrong. But Im confident that the error comes from the third line of code.

I have to admit from a novice perspective, Swift is not an easy language to learn but I'm working hard to master. Any help is appreciated.

strings.swift
// Enter your code below

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

let finalgreeting = "\(greeting)" + "How are you?"

3 Answers

Christopher David
PLUS
Christopher David
Courses Plus Student 20,027 Points

Hey Stephen. It looks like the challenge is still throwing an error because of your last variable declaration. I tried it out - changing finalgreeting to finalGreeting should do the trick.

There's a couple minor problems, easy to fix (thankfully):

  • Swift is case-sensitive, meaning that lowercase letters are different from uppercase ones. For instance, "A" is different than "a" in Swift. This means you probably change finalgreeting to finalGreeting. Don't worry; if you ran this code and you forgot to use an uppercase letter, it won't cause an error in Swift. Code challenges are just picky.
  • Don't use plus signs when concatenating.
  • If you ran your code and checked what the value of "finalGreeting" would be, it would be "Hi there, StephenHow are you?". This is happening because Swift doesn't add any extra space or anything between strings when you concatenate.

If you fix all these, your final code should look like this:

// Enter your code below

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

let finalGreeting = "\(greeting), how are you?"

On the other hand, you did a very good job!

Hope this helps, Alex

stephenallison
stephenallison
8,559 Points

Alexander, thanks so much for your response. But I'm still receiving an error code that reads "Make sure you're using concatenation to create the final string value required!".

I still have an error thats not being picked up

Hi can anyone advise on this as I have the code written as below and also still doesn't work ...

let name = "Stephen" let greeting = "Hi there, (name)" let finalGreeting = "(greeting), how are you?"

Surely this is a much more efficient code than this??

let name = "Stephen" let greeting = "Hi there, (name)" let finalGreeting = "(greeting)" + "How are you?"