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 = ["Meera", "Aman", "Arjun", "Zoya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Meera (b) Hi, Arjun (c) Hi, Zoya (d) Hi, Aman -
2.🔁 What number does this code show?
let scores = [6, 4, 6, 17];
let total = 0;
for (let i = 0; i < scores.length; i++) {
total = total + scores[i];
}
show(total); -
3.🔁 What is the LAST line this code shows?
let names = ["Zoya", "Riya", "Meera", "Kabir", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Meera (c) Hi, Zoya (d) Hi, Arjun - 4.🔁 A loop over a list of 5 items runs its body how many times? (a) 1 (b) 4 (c) 6 (d) 5
-
5.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Aman", "Riya", "Zoya", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Riya (c) Hi, Aman (d) Hi, Meera -
6.🔁 What number does this code show?
let steps = [19, 13, 16, 11];
let best = 0;
for (let i = 0; i < steps.length; i++) {
if (steps[i] > best) {
best = steps[i];
}
}
show(best); -
7.🔁 What number does this code show?
let runs = [9, 14, 10, 13, 18];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
8.🔁 What is the LAST line this code shows?
let names = ["Arjun", "Kabir", "Aman", "Meera", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Aman (c) Hi, Arjun (d) Hi, Kabir -
9.🔁 What number does this code show?
let runs = [84, 79, 29];
let count = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] >= 60) {
count = count + 1;
}
}
show(count); - 10.🔁 In for (let i = 0; i < 3; i++), which values does i take? (a) 1, 2, 3 (b) 0, 1, 2 (c) 3 (d) 0, 1, 2, 3
- 11.🔁 What does a loop do? (a) deletes code (b) draws icons (c) repeats code (d) saves photos
-
12.🔁 What number does this code show?
let runs = [63, 87, 33, 96];
let count = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] >= 70) {
count = count + 1;
}
}
show(count); -
13.🔁 What number does this code show?
let steps = [9, 8, 10, 15, 20];
let best = 0;
for (let i = 0; i < steps.length; i++) {
if (steps[i] > best) {
best = steps[i];
}
}
show(best); - 14.🔁 list.length tells you ___. (a) the first item (b) the biggest item (c) how many items it has (d) the last item
-
15.🔁 What is the LAST line this code shows?
let names = ["Riya", "Zoya", "Meera", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Arjun (b) Hi, Meera (c) Hi, Zoya (d) Hi, Riya -
16.🔁 What number does this code show?
let scores = [5, 4, 5];
let best = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] > best) {
best = scores[i];
}
}
show(best); -
17.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Arjun", "Zoya", "Meera", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Zoya (b) Hi, Kabir (c) Hi, Arjun (d) Hi, Riya -
18.🔁 What is the LAST line this code shows?
let names = ["Riya", "Aman", "Kabir", "Arjun", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Kabir (c) Hi, Meera (d) Hi, Aman -
19.🔁 What number does this code show?
let runs = [5, 6, 17];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
20.🔁 What number does this code show?
let marks = [10, 3, 10, 14, 4];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
21.🔁 What number does this code show?
let scores = [19, 2, 17, 12];
let total = 0;
for (let i = 0; i < scores.length; i++) {
total = total + scores[i];
}
show(total); -
22.🔁 What number does this code show?
let runs = [4, 12, 20, 17];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
23.🔁 What number does this code show?
let steps = [15, 17, 16, 7, 7];
let total = 0;
for (let i = 0; i < steps.length; i++) {
total = total + steps[i];
}
show(total); -
24.🔁 What is the LAST line this code shows?
let names = ["Riya", "Arjun", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Aman (b) Hi, Arjun (c) Hi, Riya -
25.🔁 What is the LAST line this code shows?
let names = ["Riya", "Zoya", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Aman (b) Hi, Riya (c) Hi, Zoya -
26.🔁 What number does this code show?
let steps = [20, 15, 14, 10, 6];
let total = 0;
for (let i = 0; i < steps.length; i++) {
total = total + steps[i];
}
show(total); -
27.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Aman", "Zoya", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Zoya (b) Hi, Meera (c) Hi, Aman (d) Hi, Kabir -
28.🔁 What number does this code show?
let marks = [15, 14, 5];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
29.🔁 What is the LAST line this code shows?
let names = ["Aman", "Kabir", "Arjun", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Arjun (b) Hi, Aman (c) Hi, Riya (d) Hi, Kabir -
30.🔁 What number does this code show?
let scores = [30, 13, 60, 36];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 40) {
count = count + 1;
}
}
show(count); -
31.🔁 What number does this code show?
let marks = [41, 99, 62, 83];
let count = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] >= 60) {
count = count + 1;
}
}
show(count); -
32.🔁 What is the LAST line this code shows?
let names = ["Zoya", "Kabir", "Meera", "Aman", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Meera (c) Hi, Zoya (d) Hi, Arjun -
33.🔁 What number does this code show?
let scores = [10, 15, 2, 1, 3];
let best = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] > best) {
best = scores[i];
}
}
show(best); -
34.🔁 What number does this code show?
let runs = [29, 78, 79, 19];
let count = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] >= 60) {
count = count + 1;
}
}
show(count); -
35.🔁 What number does this code show?
let runs = [9, 14, 3];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
36.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Aman", "Riya", "Zoya", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Arjun (c) Hi, Riya (d) Hi, Aman -
37.🔁 What number does this code show?
let scores = [92, 79, 44, 78];
let count = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] >= 40) {
count = count + 1;
}
}
show(count); -
38.🔁 What number does this code show?
let steps = [5, 6, 9, 7];
let total = 0;
for (let i = 0; i < steps.length; i++) {
total = total + steps[i];
}
show(total); -
39.🔁 What number does this code show?
let steps = [22, 32, 79];
let count = 0;
for (let i = 0; i < steps.length; i++) {
if (steps[i] >= 50) {
count = count + 1;
}
}
show(count); -
40.🔁 What number does this code show?
let marks = [1, 16, 7, 10, 12];
let best = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] > best) {
best = marks[i];
}
}
show(best);
Answer key
- Hi, Zoya
- 33
- Hi, Arjun
- 5
- Hi, Meera
- 19
- 64
- Hi, Riya
- 2
- 0, 1, 2
- repeats code
- 2
- 20
- how many items it has
- Hi, Arjun
- 5
- Hi, Riya
- Hi, Meera
- 28
- 41
- 50
- 53
- 62
- Hi, Aman
- Hi, Aman
- 65
- Hi, Meera
- 34
- Hi, Riya
- 1
- 3
- Hi, Arjun
- 15
- 2
- 26
- Hi, Arjun
- 4
- 27
- 1
- 16
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students