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

whats wrong with my code?

why is this wrong?

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

strings.swift
// Enter your code below
let name = "Russ"
let greeting = "Hi there, "
let interpolatedGreeting = "\(greeting) \(name) \(.)"

2 Answers

Brian Merwin
Brian Merwin
1,239 Points

Hi Shelli!

The code is incorrect because the period you're trying to insert into the tail end of the "interpolatedGreeting" constant does not need to be included into the escape characters \( ) - those are only for inserting constants or variables into the new string. You can instead just enter the period as is like so:

let interpolatedGreeting = "\(greeting) \(name)."

thanks, but that produces same error...

Hi Shelli,

The challenge is looking for certain things. First, a constant called name that contains a string and, second, a constant called greeting that contains the words "Hi there, " and then an interpolated insertion of the name constant.

It's not looking for a constant called interpolatedGreeting so that's why your code isn't passing the challenge. A solution to the first part of this challenge could look something like:

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

I hope that helps - let me know how you get on.

Steve.