App Dev Worksheet: Loops over Lists
Developer's tip (One by one): for (let i = 0; i < list.length; i++) visits every item, from position 0. Total: add each item. Count: add 1 when the test is true. Best: keep the biggest so far. The body runs once per item: a list of 5 runs it 5 times.
NameDateTime takenScore ___ / 40
-
1.🔁 What is the LAST line this code shows?
let names = ["Aman", "Riya", "Arjun", "Zoya", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Meera (c) Hi, Arjun (d) Hi, Aman - 2.🔁 In for (let i = 0; i < 3; i++), which values does i take? (a) 3 (b) 1, 2, 3 (c) 0, 1, 2 (d) 0, 1, 2, 3
-
3.🔁 What number does this code show?
let marks = [11, 67, 58, 96];
let count = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] >= 60) {
count = count + 1;
}
}
show(count); -
4.🔁 What is the LAST line this code shows?
let names = ["Arjun", "Meera", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Aman (b) Hi, Arjun (c) Hi, Meera -
5.🔁 What number does this code show?
let marks = [10, 6, 19, 2];
let best = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] > best) {
best = marks[i];
}
}
show(best); -
6.🔁 What number does this code show?
let scores = [42, 69, 40];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 60) {
count = count + 1;
}
}
show(count); - 7.🔁 list.length tells you ___. (a) the biggest item (b) the last item (c) the first item (d) how many items it has
-
8.🔁 What is the LAST line this code shows?
let names = ["Aman", "Zoya", "Riya", "Arjun", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Zoya (b) Hi, Meera (c) Hi, Riya (d) Hi, Aman -
9.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Zoya", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Zoya (c) Hi, Aman -
10.🔁 What is the LAST line this code shows?
let names = ["Meera", "Aman", "Zoya", "Kabir", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Meera (b) Hi, Arjun (c) Hi, Aman (d) Hi, Zoya -
11.🔁 What is the LAST line this code shows?
let names = ["Aman", "Kabir", "Riya", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Kabir (c) Hi, Arjun (d) Hi, Aman - 12.🔁 What does a loop do? (a) repeats code (b) deletes code (c) saves photos (d) draws icons
- 13.🔁 A loop over a list of 5 items runs its body how many times? (a) 1 (b) 6 (c) 5 (d) 4
-
14.🔁 What number does this code show?
let scores = [1, 4, 20, 15, 3];
let total = 0;
for (let i = 0; i < scores.length; i++) {
total = total + scores[i];
}
show(total); -
15.🔁 What number does this code show?
let runs = [15, 8, 14, 1];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
16.🔁 What is the LAST line this code shows?
let names = ["Arjun", "Kabir", "Zoya", "Meera", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Aman (b) Hi, Kabir (c) Hi, Arjun (d) Hi, Zoya -
17.🔁 What number does this code show?
let scores = [27, 41, 18, 23];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 50) {
count = count + 1;
}
}
show(count); -
18.🔁 What is the LAST line this code shows?
let names = ["Aman", "Riya", "Zoya", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Arjun (b) Hi, Riya (c) Hi, Zoya (d) Hi, Aman -
19.🔁 What number does this code show?
let marks = [16, 15, 5, 11];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
20.🔁 What number does this code show?
let marks = [33, 48, 14];
let count = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] >= 60) {
count = count + 1;
}
}
show(count); -
21.🔁 What number does this code show?
let runs = [15, 10, 8];
let best = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] > best) {
best = runs[i];
}
}
show(best); -
22.🔁 What number does this code show?
let scores = [16, 2, 1, 20, 4];
let best = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] > best) {
best = scores[i];
}
}
show(best); -
23.🔁 What number does this code show?
let runs = [1, 15, 1];
let best = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] > best) {
best = runs[i];
}
}
show(best); -
24.🔁 What number does this code show?
let scores = [30, 11, 47];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 50) {
count = count + 1;
}
}
show(count); -
25.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Aman", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Aman (c) Hi, Riya -
26.🔁 What number does this code show?
let scores = [22, 14, 61, 11];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 70) {
count = count + 1;
}
}
show(count); -
27.🔁 What number does this code show?
let runs = [3, 14, 11, 7];
let best = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] > best) {
best = runs[i];
}
}
show(best); -
28.🔁 What number does this code show?
let marks = [17, 11, 14, 3];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
29.🔁 What number does this code show?
let marks = [16, 10, 2];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
30.🔁 What number does this code show?
let steps = [11, 15, 3, 7];
let total = 0;
for (let i = 0; i < steps.length; i++) {
total = total + steps[i];
}
show(total); -
31.🔁 What number does this code show?
let scores = [8, 4, 15, 14, 20];
let total = 0;
for (let i = 0; i < scores.length; i++) {
total = total + scores[i];
}
show(total); -
32.🔁 What number does this code show?
let runs = [58, 14, 56];
let count = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] >= 40) {
count = count + 1;
}
}
show(count); -
33.🔁 What number does this code show?
let marks = [17, 15, 9, 19];
let best = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] > best) {
best = marks[i];
}
}
show(best); -
34.🔁 What is the LAST line this code shows?
let names = ["Aman", "Meera", "Arjun", "Kabir"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Aman (b) Hi, Arjun (c) Hi, Meera (d) Hi, Kabir -
35.🔁 What number does this code show?
let marks = [20, 6, 5];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
36.🔁 What number does this code show?
let runs = [6, 20, 14, 17];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
37.🔁 What number does this code show?
let scores = [46, 89, 79];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 60) {
count = count + 1;
}
}
show(count); -
38.🔁 What number does this code show?
let runs = [7, 13, 7];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
39.🔁 What is the LAST line this code shows?
let names = ["Arjun", "Riya", "Zoya", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Meera (b) Hi, Riya (c) Hi, Arjun (d) Hi, Zoya -
40.🔁 What number does this code show?
let scores = [20, 16, 18, 8, 8];
let total = 0;
for (let i = 0; i < scores.length; i++) {
total = total + scores[i];
}
show(total);
Answer key
- Hi, Meera
- 0, 1, 2
- 2
- Hi, Aman
- 19
- 1
- how many items it has
- Hi, Meera
- Hi, Aman
- Hi, Arjun
- Hi, Arjun
- repeats code
- 5
- 43
- 38
- Hi, Aman
- 0
- Hi, Arjun
- 47
- 0
- 15
- 20
- 15
- 0
- Hi, Riya
- 0
- 14
- 45
- 28
- 36
- 61
- 2
- 19
- Hi, Kabir
- 31
- 57
- 2
- 27
- Hi, Meera
- 70
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students