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