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 trialFrederik Chalmer
Courses Plus Student 354 PointsWhy 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 ;-)
// Enter your code below
let name = "Frederik"
let greeting = "Hello, \(name)"
let totalGreeting = "\(greeting). How are you?"
4 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey 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:
The challenge wants the final variable to be named "finalGreeting" and you have it named "totalGreeting"
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.
Tobias Helmrich
31,603 PointsHey 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! :)
tobiaskrause
9,160 PointsI just copy/pasted his code and it pass the challange confused
Tobias Helmrich
31,603 PointsHmmm, 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
31,603 PointsYes, 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?.
.
tobiaskrause
9,160 PointsUUhhhhh time to stop to work I'm going home :S
tobiaskrause
9,160 PointsEdit: Nothing to read here MovingOutAshamed
Jason Anders
Treehouse Moderator 145,860 PointsHey 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!
tobiaskrause
9,160 PointsI 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
31,603 PointsVery well said, Jason! I absolutely agree. You shouldn't feel ashamed, it's all about participating, not everything has to be perfect.
Steven Deutsch
21,046 PointsI 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. :)
Frederik Chalmer
Courses Plus Student 354 PointsThanks!!! This forum is amazing!