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

Clarification on the i variable

for( let i = 0; i < questions.length; i++ ) { let answer = questions[i][1]; }

It looks the i variable both represents a counter for the correct answers as well as the outer array. What does the i variable really represent in this instance? Please clarify.

Justyna Szofinska
Justyna Szofinska
6,178 Points
const grades = [
     [10,20,30,40],
     [50,60,70,80],
     [90,100,110,120]
];

You treat multiple array like a table which have rows and columns. To specify the value you need to give two informations. The first information (which represent "i" in the loop) is the number of column. The second is a number in the row. For example, "40" belongs to 0 column (because we start count from 0) and 3 row, which mean [0][3]. When you create variable for the column number like [i][3], number column will change but number of rows are constant.

I hope that I helped a little.

1 Answer

It makes a lot more sense now. Thank you very much, Justyna!