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

michael edmondson
michael edmondson
4,512 Points

Why is the first ' used after the bracket? i know why the + are used but not why [' +. why is the first ' needed?

var questionsleft = ' [' +questions + ' questionsleft]';

1 Answer

Steven Parker
Steven Parker
243,201 Points

Quote marks enclose literal strings. Everything between them will be used in building the new string. There are two literal strings in this line, one before and one after the variable. So the new string will start with an open bracket, and it will end with the words "questions left" and a close bracket.

For example, if the "questions" variable had the value of 3 in it, then "questionleft" would be assigned this:

[3 questions left]

And that becomes part of the message shown to the user.