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

Hi I'm doing these quiq challenges for IOS course and I'm stuck in one of these equations and I don't know what I miss

Hi I'm doing these quiq challenges for IOS course and I'm stuck in one of these equations and I don't know what I missing

The Quistion

Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?".

Example: "Hi there, Pasan. How are you?"

My Answer

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

Note : I ran this code on playground and it works well !

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

1 Answer

Lucian Rotari
Lucian Rotari
12,007 Points

It works well because there is no mistake, just you don't have to put in brackets ("Hi there,") because it is not a constant or a variable si just a string.

Just change this constant this way

// Your code 
let greeting = "\("Hi there,") \(name)"

// Change with this 

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

Next let have a look at our task, "Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal " How are you?"."

// 1. Declare constant (witch you have done well)
// 2.  concatenate the value (Be careful here) greeting with the string literal " How are you?"."
// NOTE: to concatenate a variable/constant with the string literal you just use + sign
let finalGreeting = greeting + " How are you?"

So again, in the playground works well because there is not mistake as syntax but you didn't respect all the tasks for the challenge that's why