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

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,558 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,558 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 :)