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

Aritro Banerjee
PLUS
Aritro Banerjee
Courses Plus Student 2,567 Points

Why is this wrong? let name="Aritro" let greeting="\("Hi there,") \(name)\(".")"

This is not being accepted as the answer to my code challenge but this works fine in the xcode playground. What is wrong?

strings.swift
// Enter your code below
let name="Aritro"

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

You're close.

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

1 Answer

Yashim Greene
Yashim Greene
866 Points

Aritro,

you only need to pass in "name" as that is the only variable that you declared.

let name="Aritro"

In the "greeting" variable you are stating what you want to say. Remember anything you place in "" Swift recognizes as a String value (or text value)

So when you do

let greeting = "Hey there, \(name)"

you are stating your "greeting" variable "Hey there, " and then you are passing in the String variable (name).

in a Swift playground try

let greeting = "Hey there, \(name)"
print (greeting)

then try

let greeting = "Hey there," \(name)
print (greeting)

Do you see the difference it makes and why you put it inside the ""

Hope this helps. Happy coding.

Don't forget the \ before your () or you'll literally print "Hey there, (name)".