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

Sterling J. Douglas
Sterling J. Douglas
173 Points

Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?"

My code is correct in xcode but the treehouse program is not accepting it? Help:

strings.swift
// Enter your code below
let name = "Pasan" 
let greeting = "Hi there"

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

let finalGreeting = "How are you?"
let concatenatedGreeting = (greeting) + ","+name+"."+(finalGreeting)
Ben Masel
Ben Masel
2,004 Points

In a minute...

1 Answer

Ben Masel
Ben Masel
2,004 Points

Hi there, Sterling! Now you've almost got it. Now string concatenation is when you stick something together. In swift it's when you close a string with a quotation mark then do a + then do antoher set of quotation marks. For e.g

strings.swift
let firstName = "Sterling"
let greeting = "Hello there, Sterling." + "How are you?" 

So your thing should look something like this:

strings.swift
// Enter your code below
let name = "Pasan" 

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

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

If this doesn't work just comment and i'll help. Good luck!