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

Albert Lee
PLUS
Albert Lee
Courses Plus Student 1,896 Points

Why do we add " + " here? var questionsLeft = "[" + questions +" questions left]" works.

as title

I think we use "+" concate nothing, I don't understand why we should use "+" before the question and after the question.

1 Answer

Steven Parker
Steven Parker
229,018 Points

The "+" is the concatenation operator, it combines strings together. The code starts with a string containing a bracket, uses the "+" to add on the number of questions, then uses another "+" to add on the rest of the message including a closing bracket.

Note that when you use this symbol with two numbers it is an addition operator instead.