Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.