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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Keith Corona
Keith Corona
9,553 Points

Amount of times looped (var 1 = 0, i < 4, i += 1)

In

(var 1 = 0, i < 4, i += 1);

does the loop run 4 times beginning with 0, 1, 2, 3 or 1, 2, 3, 4.

So something like

(var 1 = 2, i < 6, i += 1);

which runs 4 times as well would loop 2, 3, 4, 5 or 3, 4, 5, 6. I believe it is the former in each scenario, I would just like to be certain.

2 Answers

Michal Weizman
Michal Weizman
14,050 Points

Hi Keith,

You are correct. It is 2, 3, 4, 5. The addition of '+1' of i doesn't occure until the first loop is over - so during the first one it is equal to 2.

Pay attention it is supposed to be a Semicolon and not a comma between each statemen.

(var i = 2; i < 6; i += 1);

And you can't do " var 1 =2 "; it's " var i =2 "