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

Adrian Yao
Adrian Yao
1,002 Points

What is the problem with my code?

It asks me for concenatation and I think I did that with the greeting.

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

3 Answers

A few things:

  • Did you create the finalGreeting variable before defining the greeting variable? The variable greeting does not yet exist when you define finalGreeting, because you made the greeting after you made the finalGreeting variable. Try defining the finalGreeting variable after the greeting variable.
  • Why did you edit the greeting variable's text? The string was originally "Hi there, (name)", but you added a little comma after the \(name). Code challenges are extremely picky, so even a mere comma can cause a frustrating Bummer message.
  • You need to have the greeting variable outside of the quotes when concatenating greeting and "How are you?" together. Instead of"greeting + How are you?" it should be greeting + "How are you?".

I hope this helps :grin:

:dizzy: ~Alex

Jeff McDivitt
Jeff McDivitt
23,970 Points
let name = "Jeff"
let greeting = "Hi there, \(name)"
let finalGreeting = "\(greeting)" +  "How are you?"

You shouldn't just give out an answer.

The best way to learn programming is to try fixing things on your own. If you just give out an answer, people won't really think how the answer is correct, and will only copy-and-paste the answer. If you explain what's wrong and don't provide the answer, you are allowing people to understand what's wrong. If you understand what's wrong, he will never make the mistake again.

Give a man a fish, feed him a day, teach the man to fish, feed him for a lifetime :fish:

Jeff McDivitt
Jeff McDivitt
23,970 Points

Alexander Davison - I agree in which I typically do I must have forgotten to paste the other code in their other than the actual code. Which I see you have taken care of