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

So [ ] brackets are used strictly to add to prompt boxes? Do they have another use?

var questions = 3;
var questionsLeft = " [" + questions + " questions left]";
questions -= 1;
var adjective = prompt('Please type an adjective' + questionsLeft);
var verb = prompt('Please type a verb');
var noun = prompt('Please type a noun' + questionsLeft);
alert('All done. Ready for the message?');
var sentence = "<h2>There once was a " + adjective;
sentence += ' programmer who wanted to use JavaScript to ' + verb;
sentence += ' the ' + noun + '.</h2>';
document.write(sentence);

The variable questionsLeft contains a string between [ ] brackets, which adds that string to the prompt box... He may have explained the usage of those brackets but I may have missed it?

1 Answer

Hey Russell,

Normally, brackets are a way of declaring arrays or objects in JavaScript. In this case, however, they are just for punctuation's sake. He could have easily used parentheses like "(3 questions left)" or not used any punctuation at all. But, either way, in this case, the brackets hold zero significance.

Thanks Mikis!

Dana Holdt
Dana Holdt
5,578 Points

Agh. Thanks. I was left wondering the same thing.