JavaScript JavaScript Basics Working With Numbers The Mad Libs Challenge Revisited

Wardi Egal
Wardi Egal
1,735 Points

I tried to use subtract -=1 alone instead of just rewriting the questionsleft? Why cant we change a nested variable?

It looks like if we do subtract -=1 to the var questions, but it won't change it in questionsLeft unless we explicitly rewrite it in the variable even though it's embedded in the variable with the concatenation. It's probably why we use functions or conditionals but I'm wondering why!

1 Answer

Steven Parker
Steven Parker
177,673 Points

The concatenation builds up the string at the time it is performed. But the variable (such as questionsLeft) then contains only a string, nothing is left to indicate what variables (if any) were involved in creating it. So if the individual variables are changed later, the string still remains as it was until it is also reconstructed.