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 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
229,644 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: