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

larry bland
PLUS
larry bland
Courses Plus Student 7,846 Points

am i reading the question too closely based on my coding?

i need more clarity on how i should set this on up in the editor

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

greeting = "\(greeting) ,+, \(,name)"

Just looking at the javascript you've posted here, seems like you're not concatenating the string correctly. You're not escaping the variables named greeting and name. You should try something like this instead.

newGreeting = greeting + " " + name;

Currently your code returns:

"(greeting) ,+, (,name)"

You can also check your code for expected output in the chrome debug console.

andren
andren
28,558 Points

Matthew Bach While I can understand your confusion based on how the code looks, the code posted is not JavaScript. It is Swift, the programming language used mainly to develop apps for iOS.

1 Answer

andren
andren
28,558 Points

When using string interpolation you don't need to use + or commas, you just type a string like you normally would and then insert the contents of variables by wrapping the variable name in \().

To get the string you are trying to produce you would just type it like this:

"\(greeting), \(name)"

However that is not the only issue with your code, greeting is a constant. A constant is a variable which cannot have it's value reassigned. Which means that you can't set it to a different value after declaring it like you do in your code.

The solution is to use string interpolation on the string you initially assign to the greeting constant, like this:

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

Yep, I totally missed the breadcrumb showing this was in the swift track! My apologies!