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 trialNenshad Elavia
430 PointsUnary code result
if "levelscore = levelscore + 1" returns a result of 1, why does levelscore++ (which as explained in the video is technically the same as "levelscore = levelscore + 1") return a result of 0? If it's the same shouldn't the result be 1?
5 Answers
Nenshad Elavia
430 PointsThe value declared is 0. var levelScore = 0
Caleb Kleveter
Treehouse Moderator 37,862 PointsWhen you use a unary operator you call it, then add 1. So just type levelScore under levelScore++ and it will show the value 1.
Nenshad Elavia
430 PointsI don't understand why I would need to type levelScore again below?
Caleb Kleveter
Treehouse Moderator 37,862 PointsWhat is the value of levelscore to begin with?
Caleb Kleveter
Treehouse Moderator 37,862 PointsBecause it calls the variable, then adds 1 to the number.