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 Basics Swift Types String Manipulation

Murat Kuru
Murat Kuru
1,909 Points

What is wrong with my code?

What is wrong with my code? Why can't I passe the Challenge? let name = "Pasan" let greeting = "("Hi there,") (name)" let finalGreeting = "(greeting). ("How are you?")"

strings.swift
// Enter your code below
let name = "Pasan"
let greeting = "\("Hi there,") \(name)"
let finalGreeting = "\(greeting). \("How are you?")"

3 Answers

Brianna Lanz
Brianna Lanz
184 Points

let name = "Pasan" let greeting = "Hi there, (name)" let finalGreeting = greeting + "." + "How are you?"

Michael Afanasiev
PLUS
Michael Afanasiev
Courses Plus Student 15,596 Points

Hi Murat,

There is no need to interpolate every string. You only need to interpolate the name constant to "Hi there, " (mind the space). Also your finalGreeting should concatenate to the greeting constant.

For example, it should look something like this:

let myName = "Michael"
let greeting = "What's up? \(myName)" 
let final = greeting + "how ya' doin?"

Hope this helps!

The syntax for strings are being used incorrectly. There is no need to wrap them in parenthesis. In order to use a variable in string interpolation you must prefix it with a forward slash and then write the variable name in parenthesis. String are just typed out. Of course the entirety of it wrapped in double-quotes.

// Enter your code below
let name = "Pasan"
let greeting = "\("Hi there,") \(name)"
let finalGreeting = "\(greeting). \("How are you?")" 

Should be

let name = "Pasan"
let greeting = "Hi there, \(name)"
let finalGreeting = "\(greeting). How are you?"