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