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 trialArthur Kwok Wai Chui
1,462 Pointswhat's wrong?
what's wrong?
// Enter your code below
var initialScore = 8
initialScore++
let totalScore = initialScore
2 Answers
Alexander Davison
65,469 PointsTry putting the "++" part before the initialScore. Take a look here:
// Enter your code below
var initialScore = 8
// See how I put the ++ before initialScore? This should fix it :)
++initialScore
let totalScore = initialScore
Hope this helps! ~Alex
David Lin
35,864 PointsTechnically, your answer is correct, but I think their answer-checking algorithm is looking for something very specific. For example, the following passes:
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
Alexander Davison
65,469 PointsNice catch! I knew you could do that, it's just I like to keep code nice and simple so new programmers wouldn't get frustrated not understanding what's going on.
~Alex
David Lin
35,864 PointsDavid Lin
35,864 PointsAlex,
Just a note, the way he had it should've given the correct result, because the increment will occur regardless if you put the ++ before or after initialScore by the time it's assigned to totalScore since the incrementing is on a separate line.
What you said will make a difference if he put it in one line, like:
let totalScore = initalScore++ \\ <-- this won't increment initialScore before assigning to totalScore
I think it's just a bug in the coding algorithm that's not accepting his original answer, because by the time he assigns totalScore to initialScore, it is already incremented, which should be correct.