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

Zherui Li
Zherui Li
993 Points

the Meaning of '['questions+'questions left]'???

I saw someone said to treat '[' and ']' as strings, but if you write the code like : questions+questions left']' . It doesn't work!

could someone give me the official solution about this issue??

4 Answers

Steven Parker
Steven Parker
231,269 Points

That's only part of the code line. The entire line is:

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

This creates a string that has brackets in it (assuming you already have a variable named questions), which will be printed out later. Anything enclosed in quotes is a string.

:information_source: Brackets by themselves (not in a string) are used for indexing. I expect that will be covered later in the course.

Zherui Li
Zherui Li
993 Points

Thank you Steven, but if I treat it as string, and put the third quote just in front of the second bracket like this

var questionsLeft = ' [' + questions + questions left ' ] '; this code doesn't work anymore. why?

Kevin Baxter
Kevin Baxter
5,599 Points

Omg I totally get it now I was looking at the quotes in the wrong way.

Thanks Steven and all; this was not clear in the lecture. The pink is perfect and helps to see!

Sven Harder
Sven Harder
14,943 Points

questions left is a string and a part of the sentence -> it must be inside of quotes. Only questions is outside of the quotes, because it's a variable.