JavaScript JavaScript Basics (Retired) Working With Numbers The Mad Libs Challenge Revisited

Albert Lee
Albert Lee
Pro 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
201,316 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.