2-D Arrays Practice Quiz¶
Question 1¶
Rearrange the given code to create a 2 dimensional array. You can assume that the rows and cols variables have already been set as global variables.</p>
Question 2¶
2darray-quiz2: What will the following program print?:
let counter = 0;
let someArray = [[0,1,1,0],
[1,0,1,0],
[1,0,0,0],
[0,1,0,1]];
for (let i = 0; i < someArray.length; i++) {
for (let j = 0; j < someArray[i].length; j++) {
counter++;
}
}
console.log(counter);
Question 3¶
2darray-quiz3: What will the following program print?:
let counter = 0;
let someArray = [[0,1,1,0],
[1,0,1,0],
[1,0,0,0],
[0,1,0,1]];
for (let i = 0; i < someArray.length; i++) {
for (let j = 0; j < someArray[i].length; j++) {
counter += someArray[i][j];
}
}
console.log(counter);
Question 4¶
2darray-quiz4: What will the following program print?:
let counter = 0;
let someArray = [[0,1,1,0],
[1,0,1,0],
[1,0,0,0],
[0,1,0,1]];
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
counter += someArray[i][j];
}
}
console.log(counter);
Question 5¶
2darray-quiz5: What will the following program print?:
let counter = 0;
let someArray = [[0,1,1,0],
[1,0,1,0],
[1,0,0,0],
[0,1,0,1]];
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
counter += someArray[i+1][j+1];
}
}
console.log(counter);
Question 6¶
Solve the rowsWith5 CodingJS array problem.
Question 7¶
Solve the largestCol3x3 CodingJS array problem.