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", "Kabir", "Aman", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Meera (b) Hi, Kabir (c) Hi, Aman (d) Hi, Arjun - 2.🔁 In for (let i = 0; i < 3; i++), which values does i take? (a) 0, 1, 2 (b) 3 (c) 0, 1, 2, 3 (d) 1, 2, 3
-
3.🔁 What number does this code show?
let marks = [69, 67, 66];
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 = ["Riya", "Meera", "Zoya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Zoya (b) Hi, Riya (c) Hi, Meera -
5.🔁 What number does this code show?
let marks = [2, 16, 19, 14];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[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 is the LAST line this code shows?
let names = ["Arjun", "Meera", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Meera (b) Hi, Arjun (c) Hi, Riya - 8.🔁 What does a loop do? (a) deletes code (b) saves photos (c) repeats code (d) draws icons
-
9.🔁 What number does this code show?
let runs = [19, 18, 14, 8, 3];
let best = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] > best) {
best = runs[i];
}
}
show(best); -
10.🔁 What number does this code show?
let marks = [7, 13, 15];
let best = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] > best) {
best = marks[i];
}
}
show(best); -
11.🔁 What number does this code show?
let runs = [10, 23, 11];
let count = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] >= 70) {
count = count + 1;
}
}
show(count); -
12.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Riya", "Arjun", "Zoya", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Riya (c) Hi, Aman (d) Hi, Arjun - 13.🔁 Why use a loop to show 100 messages? (a) less code to write (b) it is slower (c) it uses more lines (d) it hides them
-
14.🔁 What is the LAST line this code shows?
let names = ["Meera", "Kabir", "Riya", "Zoya", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Arjun (c) Hi, Kabir (d) Hi, Meera -
15.🔁 What number does this code show?
let marks = [16, 11, 5];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
16.🔁 What number does this code show?
let scores = [14, 19, 1];
let best = 0;
for (let i = 0; i < scores.length; i++) {
if (scores[i] > best) {
best = scores[i];
}
}
show(best); -
17.🔁 What number does this code show?
let marks = [11, 21, 40, 26, 15];
let count = 0;
for (let i = 0; i < marks.length; i++) {
if (marks[i] >= 60) {
count = count + 1;
}
}
show(count); - 18.🔁 A loop over a list of 5 items runs its body how many times? (a) 1 (b) 6 (c) 4 (d) 5
-
19.🔁 What number does this code show?
let steps = [9, 5, 10, 15];
let total = 0;
for (let i = 0; i < steps.length; i++) {
total = total + steps[i];
}
show(total); -
20.🔁 What is the LAST line this code shows?
let names = ["Meera", "Zoya", "Arjun", "Riya", "Kabir"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Meera (c) Hi, Zoya (d) Hi, Arjun -
21.🔁 What is the LAST line this code shows?
let names = ["Arjun", "Kabir", "Aman", "Meera"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Meera (b) Hi, Arjun (c) Hi, Aman (d) Hi, Kabir -
22.🔁 What is the LAST line this code shows?
let names = ["Meera", "Kabir", "Riya", "Arjun", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Aman (b) Hi, Riya (c) Hi, Kabir (d) Hi, Meera -
23.🔁 What number does this code show?
let runs = [18, 72, 14];
let count = 0;
for (let i = 0; i < runs.length; i++) {
if (runs[i] >= 50) {
count = count + 1;
}
}
show(count); -
24.🔁 What number does this code show?
let runs = [12, 7, 16, 6];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
25.🔁 What number does this code show?
let steps = [18, 8, 13, 5, 7];
let best = 0;
for (let i = 0; i < steps.length; i++) {
if (steps[i] > best) {
best = steps[i];
}
}
show(best); -
26.🔁 What number does this code show?
let steps = [62, 40, 62, 98, 56];
let count = 0;
for (let i = 0; i < steps.length; i++) {
if (steps[i] >= 60) {
count = count + 1;
}
}
show(count); -
27.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Meera", "Zoya", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Kabir (c) Hi, Zoya (d) Hi, Meera -
28.🔁 What is the LAST line this code shows?
let names = ["Aman", "Arjun", "Zoya", "Riya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Zoya (b) Hi, Riya (c) Hi, Aman (d) Hi, Arjun -
29.🔁 What number does this code show?
let scores = [12, 15, 7];
let total = 0;
for (let i = 0; i < scores.length; i++) {
total = total + scores[i];
}
show(total); -
30.🔁 What number does this code show?
let marks = [19, 19, 6, 7];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
31.🔁 What is the LAST line this code shows?
let names = ["Meera", "Arjun", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Arjun (b) Hi, Aman (c) Hi, Meera -
32.🔁 What is the LAST line this code shows?
let names = ["Arjun", "Kabir", "Riya", "Zoya", "Aman"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Kabir (b) Hi, Arjun (c) Hi, Aman (d) Hi, Riya -
33.🔁 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, Aman (b) Hi, Kabir (c) Hi, Riya -
34.🔁 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, Riya (b) Hi, Zoya (c) Hi, Meera (d) Hi, Aman -
35.🔁 What number does this code show?
let marks = [9, 4, 10, 1, 7];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total); -
36.🔁 What is the LAST line this code shows?
let names = ["Aman", "Kabir", "Arjun"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Arjun (b) Hi, Kabir (c) Hi, Aman -
37.🔁 What number does this code show?
let steps = [93, 93, 34];
let count = 0;
for (let i = 0; i < steps.length; i++) {
if (steps[i] >= 40) {
count = count + 1;
}
}
show(count); -
38.🔁 What is the LAST line this code shows?
let names = ["Kabir", "Riya", "Zoya"];
for (let i = 0; i < names.length; i++) {
show("Hi, " + names[i]);
} (a) Hi, Riya (b) Hi, Zoya (c) Hi, Kabir -
39.🔁 What number does this code show?
let runs = [18, 6, 15, 14];
let total = 0;
for (let i = 0; i < runs.length; i++) {
total = total + runs[i];
}
show(total); -
40.🔁 What number does this code show?
let marks = [5, 4, 6, 2];
let total = 0;
for (let i = 0; i < marks.length; i++) {
total = total + marks[i];
}
show(total);
Answer key
- Hi, Arjun
- 0, 1, 2
- 3
- Hi, Zoya
- 51
- how many items it has
- Hi, Riya
- repeats code
- 19
- 15
- 0
- Hi, Aman
- less code to write
- Hi, Arjun
- 32
- 19
- 0
- 5
- 39
- Hi, Kabir
- Hi, Meera
- Hi, Aman
- 1
- 41
- 18
- 3
- Hi, Riya
- Hi, Riya
- 34
- 51
- Hi, Aman
- Hi, Aman
- Hi, Riya
- Hi, Meera
- 31
- Hi, Arjun
- 2
- Hi, Zoya
- 53
- 17
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students