← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 972 · 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 does a loop do? (a) saves photos (b) deletes code (c) repeats code (d) draws icons
  2. 2.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Kabir", "Arjun", "Aman", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Arjun (c) Hi, Kabir (d) Hi, Meera
  3. 3.🔁 A loop over a list of 5 items runs its body how many times? (a) 6 (b) 1 (c) 5 (d) 4
  4. 4.🔁 What is the LAST line this code shows?
    let names = ["Meera", "Aman", "Kabir", "Riya", "Arjun"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Arjun (c) Hi, Meera (d) Hi, Kabir
  5. 5.🔁 What number does this code show?
    let runs = [32, 49, 69];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  6. 6.🔁 What number does this code show?
    let runs = [20, 20, 3, 2];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  7. 7.🔁 What number does this code show?
    let scores = [4, 2, 7];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  8. 8.🔁 What number does this code show?
    let marks = [6, 7, 6, 5];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  9. 9.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Riya", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Zoya (c) Hi, Aman
  10. 10.🔁 What number does this code show?
    let runs = [4, 17, 16, 20, 8];
    let best = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] > best) {
        best = runs[i];
      }
    }
    show(best);
  11. 11.🔁 What number does this code show?
    let marks = [88, 38, 26, 83];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  12. 12.🔁 list.length tells you ___. (a) the biggest item (b) the first item (c) the last item (d) how many items it has
  13. 13.🔁 What number does this code show?
    let marks = [15, 12, 5];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  14. 14.🔁 What number does this code show?
    let runs = [2, 8, 2, 9];
    let best = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] > best) {
        best = runs[i];
      }
    }
    show(best);
  15. 15.🔁 What number does this code show?
    let marks = [20, 20, 9];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  16. 16.🔁 What number does this code show?
    let marks = [12, 10, 2, 14];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  17. 17.🔁 What number does this code show?
    let scores = [5, 11, 1, 10];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  18. 18.🔁 What number does this code show?
    let marks = [3, 4, 14, 12];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  19. 19.🔁 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, Riya (b) Hi, Meera (c) Hi, Arjun
  20. 20.🔁 What number does this code show?
    let marks = [19, 12, 6, 10];
    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 runs = [12, 18, 9];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  22. 22.🔁 What number does this code show?
    let marks = [10, 20, 18, 10, 18];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  23. 23.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Zoya", "Meera", "Aman", "Kabir"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Kabir (c) Hi, Zoya (d) Hi, Meera
  24. 24.🔁 What number does this code show?
    let marks = [30, 76, 46, 36];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  25. 25.🔁 What number does this code show?
    let scores = [16, 1, 1, 14, 1];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  26. 26.🔁 What number does this code show?
    let runs = [1, 9, 18, 12, 7];
    let best = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] > best) {
        best = runs[i];
      }
    }
    show(best);
  27. 27.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Kabir", "Meera", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Aman (c) Hi, Kabir (d) Hi, Riya
  28. 28.🔁 What number does this code show?
    let marks = [14, 1, 17, 15];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  29. 29.🔁 What number does this code show?
    let scores = [7, 15, 10];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  30. 30.🔁 What number does this code show?
    let steps = [17, 2, 4, 6, 3];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  31. 31.🔁 What number does this code show?
    let marks = [8, 15, 5, 17];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  32. 32.🔁 What number does this code show?
    let marks = [6, 7, 13, 14, 17];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  33. 33.🔁 What number does this code show?
    let steps = [32, 76, 73, 40, 42];
    let count = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  34. 34.🔁 What number does this code show?
    let marks = [17, 2, 3, 15];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  35. 35.🔁 What number does this code show?
    let scores = [15, 2, 13, 13, 13];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  36. 36.🔁 What number does this code show?
    let marks = [35, 66, 27, 81, 23];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  37. 37.🔁 What number does this code show?
    let runs = [2, 20, 6];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  38. 38.🔁 What is the LAST line this code shows?
    let names = ["Meera", "Aman", "Riya", "Arjun", "Kabir"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Kabir (b) Hi, Aman (c) Hi, Riya (d) Hi, Meera
  39. 39.🔁 What number does this code show?
    let scores = [27, 28, 21, 43];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  40. 40.🔁 What number does this code show?
    let scores = [18, 9, 11];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);

Answer key

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

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