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

I am not getting the right answer and i don't know what i am doing wrong

let name = "mackenzie" let greeting = "hi there," interpolatedGreeting = "(greeting), (name)"

strings.swift
let name = "Mackenzie"
let greeting = "Hi there,"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Mackenzie Kirkham!

I think maybe you misunderstood what they meant by the interpolated greeting. They weren't looking for a variable named that. What they want is for greeting to say "Hi there, Mackenzie". Without you writing it out. Now in Swift there are two ways of putting together strings. There's concatenation. And there's interpolation. Concatenation is simply using a plus sign. And we'd write that as such:

let word1 = "Hello "
let word2= "world!"
return word1 + word2

This code would return the full string of "Hello world!". That's concatenation.

It's asking for interpolation which is the use of a backslash and parentheses to mark the space where you want to put the value of a variable. Take a look:

// Enter your code below
let name = "Mackenzie"
let greeting = "Hi there, \(name)."

Now greeting is equal to "Hi there, Mackenzie.". If you were to leave off the backslash and parentheses the greeting would be equal to "Hi there, name.". Which, obviously, isn't what you're after.

Hope this helps! :smiley:

Thank you so much! that makes more sense!