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

Question about closing quote on Line 2 - confused

Hi there - just wondering about the opening and closing quote marks on this line 2?

var questionsLeft = ' [' + questions + ' questions left]';

specicially the ones here [' + questions +'.....

why are we dividing the line like this?

Cheers

2 Answers

Steven Parker
Steven Parker
243,670 Points

This is an example of concatentation, which is what the plus-sign operator (+) does with strings. Some of the parts being joined together are literal, and those are enclosed in quotes. This first is just a bracket ('['), the last is some words and a closing bracket (' questions left]'). Sandwiched in between the value of the variable questions.

So, if questions contained the number 7, or the string '7', after this assignment questionsLeft would have this string in it:

[7 questions left]

Does it make sense now?

aha! I see Steven - I understand now that the '[' is part of the string while the questions is the variable...got it got it got - the brackets confused me... thanks