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

Saira Bottemuller
PLUS
Saira Bottemuller
Courses Plus Student 1,749 Points

Question re: syntax (JavaScript Mad Libs Challenge Revisited)

Hello all! :)

I just completed the Mad Libs Challenge Revisited project, and it worked, but I have a question about the syntax because there's something I'm not clear on.

it's in this portion:

questions -= 1;
questionsLeft = ' [' + questions + ' questions left]'; ```

I was wondering about the apostrophe/quote marks. My understanding is that when you use quote marks, and then have to nest additional quote marks inside them, you should use them in sets of ' ' and " ", so the program won't get confused. A ' will close the last ' that was entered, and a " will close the last ". So under that logic, in this snippet of code, it seems like the first ' should close right after the [.... but I guess that's wrong in this case? Can anyone explain to me what's going on with this? Thank you for taking the time. :)

2 Answers

Colin Bell
Colin Bell
29,679 Points

A ' will close the last ' that was entered, and a " will close the last ". So under that logic, in this snippet of code, it seems like the first ' should close right after the [...

You're absolutely correct. In this case, we actually do want to close that string right after the [ then concatenate what the questions variable is equal to (instead of the actual word "questions") to the string, then concatenate the rest of the string to the end of that.

So if you had something like

var questions = 7;
questions -= 1; 
var questionsLeft = ' [' + questions + ' questions left]';
console.log(questionsLeft);

The console would log: [6 questions left]

Since in this case: questions === 6.

Saira Bottemuller
PLUS
Saira Bottemuller
Courses Plus Student 1,749 Points

Ohhhh I see, I see! Thank you so much, that totally makes sense now. Thanks for your help! :D