Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript The Solution

Jong Kim
Jong Kim
6,145 Points

Why do we need a bracket even though we have parenthesis?

Why don't we just put everything inside of parenthesis?

for example,

Why can't we just put everything inside of parenthesis?? for (i = 0; i <= 5; i += 1; text += i + ' ')

What is the purpose of separating a parenthesis and bracket?

Why do we have to write ' text += i + ' '; ' inside of bracket instead just write down into the parenthesis?

1 Answer

Steven Parker
Steven Parker
221,291 Points

You could certainly make it work that way, and technically, I'd call that a legitimate alternative solution.

But it's a rather unconventional way to construct a loop, and its purpose might not be as immediately clear to someone reading the code. So for that reason I don't think it would qualify as a "best practice".

However, I must admit that I have made loops like that myself on occasion. :smiling_imp: