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

JavaScript JavaScript Basics (Retired) Working With Numbers Doing Math

Updating a variable

Could someone please explain to me why at 2:00 why is it score = score + 100; instead of score = 100; ?

Thanks

3 Answers

If you set the score as equal to 100, it will always be 100.

What would happen when you want to add another 100 to a score of 100?

The "score" variable is used to keep track of the score and is updated when something happens.

So if the current score is 1000, the next score will be 1000 (score) + 100, giving you 1100

So if I just went Var Score = 100

Then

Var Score = 200 it would just change the value to 200 instead of adding the two together ?

Can I achieve a score of 300 by going Var score = 100

score += 200

Thanks

Yes that is exactly correct :D

Awesome, thank you!