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

Concatenation

Still need help with this (sorry!)

I need to declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?".

Example: "Hi there, Ruby. How are you?"

I am still getting an error message! : (

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

4 Answers

Bradley Gilmore
PLUS
Bradley Gilmore
Courses Plus Student 2,558 Points

Ok ruby1 I've added the answer here since it appears your still having trouble.. I encourage you to try and go back into your code though and figure out exactly what you were doing wrong though, instead of just copying and pasting. Thanks and good luck in future challenges!

let name: String = "Example Name" let greeting = "Hi there, \(name)

Hi Bradley - thank you for getting back to me again. You have given me guidance to answer task 1, which I managed to do no problem on my own. However, it is task 2 that I am stuck on: I need to declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?". I have played around with possibilities, but I keep getting an error message. : (

Bradley Gilmore
Bradley Gilmore
Courses Plus Student 2,558 Points

Ah I'm sorry I completely misread your post. This is the solution. Perhaps you were trying to interpolate instead of using concatenation?

let name: String = "Example Name" let greeting = "Hi there, (name)" let finalGreeting = greeting + "How are you?"

Bradley - for some reason I don't have the option to selection Best Answer for your last response to me.
let finalGreeting = greeting + "How are you?" This worked - hooray! : ) Thank you for helping me more forward! : )

Michael Afanasiev
PLUS
Michael Afanasiev
Courses Plus Student 15,596 Points

Hi Ruby! ?

You are using the addition operator(+) within your string, that won't work! You need to concatenate 2 strings.

Hope this helps! ?

Bradley Gilmore
PLUS
Bradley Gilmore
Courses Plus Student 2,558 Points

Hi there, looks like you may need to have a couple more (") marks there. As a hint you can't use the operator (+) within a string, try using it out of the string. Goodluck!

Matthew Ingram
PLUS
Matthew Ingram
Courses Plus Student 4,718 Points

Since you're within the string you don't need to add the + sign,

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

Hi Matthew - thanks for responding to my question. I tried it but it gives me this error message: Make sure you're using concatenation to create the final string value required!

: (