← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 247 · 40 questions
TalentJR

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. 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. 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. 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. 4.🔁 A loop over a list of 5 items runs its body how many times? (a) 1 (b) 4 (c) 6 (d) 5
  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. 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. 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. 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. 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. 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. 11.🔁 What does a loop do? (a) deletes code (b) draws icons (c) repeats code (d) saves photos
  12. 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. 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. 14.🔁 list.length tells you ___. (a) the first item (b) the biggest item (c) how many items it has (d) the last item
  15. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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

  1. Hi, Zoya
  2. 33
  3. Hi, Arjun
  4. 5
  5. Hi, Meera
  6. 19
  7. 64
  8. Hi, Riya
  9. 2
  10. 0, 1, 2
  11. repeats code
  12. 2
  13. 20
  14. how many items it has
  15. Hi, Arjun
  16. 5
  17. Hi, Riya
  18. Hi, Meera
  19. 28
  20. 41
  21. 50
  22. 53
  23. 62
  24. Hi, Aman
  25. Hi, Aman
  26. 65
  27. Hi, Meera
  28. 34
  29. Hi, Riya
  30. 1
  31. 3
  32. Hi, Arjun
  33. 15
  34. 2
  35. 26
  36. Hi, Arjun
  37. 4
  38. 27
  39. 1
  40. 16

Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students