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

Why is this wrong?

Why is this wrong? I think i have tried everything! This is what i think is the best method, but im curious about whats right ;-)

strings.swift
// Enter your code below

let name = "Frederik"

let greeting = "Hello, \(name)"
let totalGreeting = "\(greeting). How are you?"

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Frederik,

While the code is syntactically correct, it is not passing Task 2 because it isn't what the challenge asked you to do. The challenges are very specific and very picky. So, with that said, there are two minor errors:

  1. The challenge wants the final variable to be named "finalGreeting" and you have it named "totalGreeting"

  2. For the finalGreeting, the challenge wants the sentence constructed using Sting Concatenation and you used String Interpolation.

The corrected code will look like this:

let name = "Frederik"

let greeting = "Hello, \(name)"
let finalGreeting = greeting + " How are you?"

Hope that makes sense and helps. :dizzy:

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey there,

actually the code itself is fine but it is not passing for two reasons: Firstly the last constant should be called finalGreeting instead of totalGreeting . The other problem is that you have to use concatenation for the finalGreeting constant but you're using interpolation right now, so you have to use a "+" to add both Strings together. Also don't forget to add a period after the greeting.

It should work like this:

// Enter your code below

let name = "Frederik"

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

I hope that helps! :)

I just copy/pasted his code and it pass the challange confused

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hmmm, are you sure you checked both tasks? The first task passes because it's just about creating the greeting constant. The second task however doesn't pass.

Tobias Helmrich
Tobias Helmrich
31,603 Points

Yes, that's the description for the first task. The second task clearly says: Declare a constant named finalGreeting, and concatenate the value of greeting with the string literal How are you?. .

UUhhhhh time to stop to work I'm going home :S

Edit: Nothing to read here MovingOutAshamed

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hey Tobias Krause

Really no need to be. Errors are a part of the learning process. Trust me, I've made my share and sometimes still do. But, participating in the forum is one of the great ways of learning here on Treehouse, even if your answer may not be 100% correct, others will come around and provide a correction, share their thoughts and code, engage in debate, etc... and thus, learning occurs. Thank-you for participating, and Keep Coding! :dizzy:

I would not be ashamed if it would be a coding mistake...but USUALLY i read carefully...seems I am not concentrated today...but like wrote -> time to stop working...I'll go home ;)

Also I tell people A LOT to read the challange descriptions carefully...and then this mistake hits me :D Maybe ashmed is not the right word (too strong?) but my english skills are not that good

Tobias Helmrich
Tobias Helmrich
31,603 Points

Very well said, Jason! I absolutely agree. You shouldn't feel ashamed, it's all about participating, not everything has to be perfect.

Steven Deutsch
Steven Deutsch
21,046 Points

I look at responses I wrote 3 weeks ago and give myself an occasional face palm! One time I wrote a 5 paragraph response explaining how to do a challenge and it turns out the guy was just missing a bracket. :)

Thanks!!! This forum is amazing!