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

kabirdas
kabirdas
1,976 Points

What is the purpose the brackets []?

This question was already asked, but my question is still not resolved. Why isn't:

var questionsLeft = questions + " left";

also acceptable?

4 Answers

andren
andren
28,558 Points

They don't serve any purpose beyond styling the output. They are in no way essential. If you prefer not to include them then that won't affect anything but how it looks when it is printed out.

Dave wanted the output to look like this:

[x questions left]

With your code it will look like this:

x left

In both of these examples x is a placeholder for the number of questions.

So to answer your question more directly, both would be equally acceptable. In programming there is rarely (almost never) only one acceptable way of doing something. And that is especially true when it comes to how you style output from your program, as styling is an inherently opinion driven thing.

thanks, great explanation, now it's clear to me as well!!!

Omar Elfishawi
Omar Elfishawi
4,060 Points

yeah that was driving me mad...