JavaScript JavaScript Basics 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
PRO
Jacques Butcher
Pro Student 3,995 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.

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,734 Points

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