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

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
231,236 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.