← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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