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

Johnny Tran
Johnny Tran
5,333 Points

+ signs on both sides of question var. What is it for?

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

Hi, can someone please explain what the two + signs on either side of question var is. I deleted them from my code and the page stopped working but I dont understand why.

Thanks

3 Answers

The '+' signs are used for concatenation. It joins your strings together with the variables to create one string. let's say questions = 5, in this case, then it would read: '[ 5 questions left ]'

Johnny Tran
Johnny Tran
5,333 Points

Thank you. But why one + at the front of questions +questions+?

The original code is: questionsLeft = ' [' +questions+ ' questions left]';

Is this code the same as

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

Thanks a bunch!

because there's strings on both sides of the variable: '[' and 'questions left]'

Jesse Hall
Jesse Hall
4,275 Points

The first + is there because we wanted to include a [ in our message (along with a space after it) then comes your + to include the variable question.