← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 186 · 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 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. 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. 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. 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. 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. 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. 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. 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. 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. 10.🔁 A loop over a list of 5 items runs its body how many times? (a) 6 (b) 4 (c) 5 (d) 1
  11. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 37.🔁 What does a loop do? (a) saves photos (b) draws icons (c) repeats code (d) deletes code
  38. 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. 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. 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. 1
  2. 32
  3. 0
  4. 20
  5. Hi, Kabir
  6. 58
  7. 0
  8. 0
  9. Hi, Arjun
  10. 5
  11. 20
  12. Hi, Zoya
  13. 14
  14. 19
  15. 41
  16. 42
  17. Hi, Kabir
  18. 20
  19. Hi, Riya
  20. 0
  21. Hi, Riya
  22. Hi, Meera
  23. Hi, Arjun
  24. 24
  25. 41
  26. 13
  27. 15
  28. 34
  29. Hi, Arjun
  30. Hi, Kabir
  31. 30
  32. Hi, Zoya
  33. Hi, Arjun
  34. 2
  35. 44
  36. 2
  37. repeats code
  38. 2
  39. Hi, Arjun
  40. 18

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