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 The Mad Libs Challenge Revisited

Jacques Andre
Jacques Andre
2,780 Points

Why do we have to repeat the questionsLeft? How does JS not know that it has been updated

How does JS not know that the questions has been decreased and use that value for the questionsLeft variable?

2 Answers

Jacques Butcher
PLUS
Jacques Butcher
Courses Plus Student 4,102 Points

Once you assigned the value of questions (3 the first time) to questionstLeft it won't update itself within questionsLeft automatically even if you update the value for questions. You have to therefore create the questionsLeft string again (destroying the previous one) with the new value for questions after you subtracted one from it.

questions and questionsLeft are independent variables. Their values will only change with the assignment operator.