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 trialZherui Li
993 Pointsthe 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
231,269 PointsThat'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.
Brackets by themselves (not in a string) are used for indexing. I expect that will be covered later in the course.
Kevin Baxter
5,599 PointsOmg I totally get it now I was looking at the quotes in the wrong way.
y1n5
2,626 PointsThanks Steven and all; this was not clear in the lecture. The pink is perfect and helps to see!
Sven Harder
14,943 Pointsquestions 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.
Zherui Li
993 PointsZherui Li
993 PointsThank 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?