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

Tre Bu
Tre Bu
1,521 Points

Confusion on the '[' + questions + ' questions left]'

Could someone explain why you have the apostrophes go where they are here?

Do the ' outside the brackets represent the whole string and the ' inside the brackets convert the 3 to a string and add spacing?

2 Answers

Steven Parker
Steven Parker
231,236 Points

The apostrophes (also known as "single quotes") enclose literal strings. The brackets are entirely inside the strings and have no meaning to the code. The syntax coloring provided by the formatter may help clarify this:

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

Note that the strings are a different color than the code. The system automatically coerces (converts) the number in "questions" into a string when it is combined with the other strings by the + operator.

Tre Bu
Tre Bu
1,521 Points

I understand now, thank you so much for the help!

Best

Steven Parker
Steven Parker
231,236 Points

Tre Bu — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!