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

Jack Pannekoek
seal-mask
.a{fill-rule:evenodd;}techdegree
Jack Pannekoek
iOS Development Techdegree Student 1,590 Points

Why does the "Check Work" return 'Bummer' when the code executes just fine and produces the requested result?

I ran the code and it produces the requested result for this exercise question and as far as I understand, the directions provided were followed.

strings.swift
// Enter your code below

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

1 Answer

andren
andren
28,558 Points

While you are right about your code producing the right output, the challenge checker tends to be quite picky, not just about what the result of your code is but also how that result is achieved.

In your code you combine the strings together using what is called string interpolation (using a string that contains a placeholder), but the task specifically asks you to use string concatenation to combine the strings.

String concatenation is the simpler way of combining strings where you combine them using the + symbol like this:

"String1" + "string2" producing the string "String1string2"

So the solution to the task is this:

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

Again there is nothing technically wrong with your solution. I tend to prefer string interpolation over string concatenation myself. But in this case the challenge specifically asked for concatenation, so that is what you have to use to complete the challenge.