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 trialTom Lawrence
8,685 Points' [' + questions + ' questions left]'
Hi,
I do not really understand the reason for the first ' or the structure of this statement really, I understand what it does but not now!
var questionsLeft = ' [' + questions + ' questions left]'
I would have expected it to be done like this:
var questionsLeft = " " + questions + " Questions Left";
both obviously work but nice to know / understand the first one :)
4 Answers
Florin Veja
6,912 PointsTom,
var questions = 5;
var questionsLeft = ' [' + questions + ' questions left]';
After running, would leave the variable questionsLeft to be "[5 questions left]", without the quotes.
var questions = 5;
var questionsLeft = " " + questions + " Questions Left";
Would leave the variable questionsLeft with the value " 5 Questions Left", without the quotes.
Notice, the second code does not have the square brackets. [ and ]. There is no reason for having the [ and ] in the first code. except to display them.
Hope that helps.
Michael Jurgensen
8,341 PointsHi Tom,
These two pieces of code are very similar. The first will print a set of literal square brackets with the number of questions remaining like this:
(Assuming there is 1 question remaining)
" [1 questions left]"
The other section of code will print:
" 1 Questions Left"
I hope that clears up any confusion.
Tom Lawrence
8,685 PointsOh I didnt even notice it was printing the [], I was thinking it was some crazy array I have never seen before inside speach marks!
Thanks for that
E P
2,215 Pointsyes I had the same confusion because of the brackets! LOL thanks for clearing this up.