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

Andreas Wagner
Andreas Wagner
5,471 Points

Hi there! just started this course, and I am stuck because my code works in the playground but not here

I copy&pasted this code from the playground in here.

strings.swift
// Enter your code below

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

let finalGreeting = "\(greeting) How are you?"

3 Answers

andren
andren
28,520 Points

The third tasks asks you to combine the strings using concatenation, you are using interpolation.

To concatenate two strings you have to use the + operator on them. Like this:

let finalGreeting = greeting + " How are you?" // Concatenate greeting to " How are you?"

Concatenation and interpolation will result in the same string, but they are different techniques. Both of them are pretty commonly used which is why the challenge wants to ensure you are familiar with them.

Andreas Wagner
Andreas Wagner
5,471 Points

Aaaahaha, I am sometimes a little boneheaded! Thank you so much!

andren
andren
28,520 Points

Nah this is a very common task for students to have trouble with, so you don't have to feel too bad :smile:.

Since the techniques produce the same string they are often treated as interchangeable (and generally they are) so having a challenge that rejects code just based on the technique used to combine the strings is somewhat harsh.

Andreas Wagner
Andreas Wagner
5,471 Points

that´s what I had problems with the first time that I tried teaching myself code... I still prefer this interactive method over other courses that I can just follow along via video, so I´ll keep on trying :)