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 trialJohnny 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
David Tonge
Courses Plus Student 45,640 PointsThe '+' 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 ]'
Jesse Hall
4,275 PointsThe 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.
Michael Schomburg
Front End Web Development Techdegree Student 9,887 PointsThis was very helpful, I could not see the 2 strings.
Johnny Tran
5,333 PointsJohnny Tran
5,333 PointsThank 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!
David Tonge
Courses Plus Student 45,640 PointsDavid Tonge
Courses Plus Student 45,640 Pointsbecause there's strings on both sides of the variable: '[' and 'questions left]'