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 trialJohn Moron
1,658 PointsWhat is the value of totalScore? var totalScore = 10 - 20 ++totalScore
I don't understand this question.
3 Answers
Logan R
22,989 PointsWhat is the value of totalScore?
var totalScore = 10 - 20
++totalScore
So what is happening is it is declaring a variable called totalScore. Total score is initialized with (10 - 20), so the initial value of totalScore is equal to -10.
With the ++ and -- operator, it is the same as saying:
totalScore = totalScore + 1
It is just a really shortened way of saying it.
The answer to the question is -9.
var totalScore = 10 - 20 // This equals -10
++totalScore // This takes -10 and adds one to make -9
agreatdaytocode
24,757 PointsHi John
If you put this into a playground file you will get the answer
var totalScore = 10 - 20 \\ - 10
++totalScore \\ -9
John Moron
1,658 Pointsohh I got it now thanks.
Logan R
22,989 PointsNo problem! If you need any further clarification, just simply ask :)
John Moron
1,658 PointsI will do that :)