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

When I run this code in Xcode i get no error, but I'm getting an error on here, what's wrong?

I'm very new to this, but I'm not sure exactly what's wrong.

strings.swift
// Enter your code below

let name = "Elijah"

let greeting = "Hi there,"

let greetingName = greeting +  "\(name)"

2 Answers

Keli'i Martin
Keli'i Martin
8,227 Points

From the question: "Second, declare a constant named greeting. Set the value of greeting to an interpolated string that combines "Hi there, " with the string stored in the name constant."

What they are asking for is a second constant that combined the literal string "Hi there, " with the string stored in the name constant. Your code would then look like this:

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

Hope this helps!

I think you're now mixing two things, String interpolation and concatenating! String values can be added together (or concatenated) with the addition operator (+) to create a new String value:

let name = "Elijah"

let greeting = "Hi there,"

let greetingName = greeting +  name

In String interpolation you're making a new string by mixing constants and literals. In this case you'd include the value of the Name -constant inside a String:

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