← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 560 · 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 scores = [16, 4, 2];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  2. 2.🔁 What number does this code show?
    let marks = [17, 12, 1, 16, 9];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  3. 3.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Zoya", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Arjun (c) Hi, Zoya
  4. 4.🔁 What does a loop do? (a) repeats code (b) saves photos (c) draws icons (d) deletes code
  5. 5.🔁 What is the LAST line this code shows?
    let names = ["Zoya", "Aman", "Kabir", "Arjun", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Meera (c) Hi, Kabir (d) Hi, Zoya
  6. 6.🔁 A loop over a list of 5 items runs its body how many times? (a) 1 (b) 6 (c) 4 (d) 5
  7. 7.🔁 list.length tells you ___. (a) the first item (b) the biggest item (c) how many items it has (d) the last item
  8. 8.🔁 What number does this code show?
    let scores = [18, 6, 5, 13];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  9. 9.🔁 What number does this code show?
    let scores = [13, 12, 20, 19, 4];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  10. 10.🔁 What number does this code show?
    let scores = [5, 8, 8, 18];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  11. 11.🔁 What number does this code show?
    let marks = [54, 95, 89, 25, 68];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  12. 12.🔁 What number does this code show?
    let runs = [89, 97, 35, 27];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  13. 13.🔁 Why use a loop to show 100 messages? (a) it hides them (b) it uses more lines (c) it is slower (d) less code to write
  14. 14.🔁 What number does this code show?
    let marks = [57, 83, 18, 51, 34];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  15. 15.🔁 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, Aman (c) Hi, Kabir
  16. 16.🔁 What number does this code show?
    let scores = [7, 15, 20];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  17. 17.🔁 What number does this code show?
    let scores = [49, 97, 76, 64, 76];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  18. 18.🔁 What number does this code show?
    let steps = [18, 4, 5];
    let best = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] > best) {
        best = steps[i];
      }
    }
    show(best);
  19. 19.🔁 What number does this code show?
    let scores = [9, 2, 13];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  20. 20.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Zoya", "Riya", "Meera", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Zoya (b) Hi, Aman (c) Hi, Arjun (d) Hi, Riya
  21. 21.🔁 What number does this code show?
    let scores = [15, 1, 12, 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 scores = [12, 9, 16];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  23. 23.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Riya", "Arjun", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Aman (c) Hi, Zoya (d) Hi, Arjun
  24. 24.🔁 What number does this code show?
    let runs = [31, 96, 46];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 40) {
        count = count + 1;
      }
    }
    show(count);
  25. 25.🔁 What number does this code show?
    let steps = [4, 13, 7, 17, 7];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  26. 26.🔁 What number does this code show?
    let marks = [3, 15, 13, 12, 8];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  27. 27.🔁 What number does this code show?
    let steps = [14, 15, 9, 16];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  28. 28.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Meera", "Arjun", "Zoya", "Kabir"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Arjun (b) Hi, Kabir (c) Hi, Aman (d) Hi, Meera
  29. 29.🔁 What number does this code show?
    let scores = [18, 12, 2, 11];
    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 runs = [89, 63, 19, 58, 18];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  31. 31.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Kabir", "Zoya", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Kabir (b) Hi, Arjun (c) Hi, Zoya (d) Hi, Aman
  32. 32.🔁 What number does this code show?
    let scores = [3, 2, 1];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  33. 33.🔁 What number does this code show?
    let marks = [10, 7, 19, 17];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  34. 34.🔁 What number does this code show?
    let scores = [15, 3, 4, 6];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  35. 35.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Kabir", "Arjun", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Kabir (c) Hi, Arjun (d) Hi, Meera
  36. 36.🔁 What number does this code show?
    let steps = [19, 11, 7, 7];
    let best = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] > best) {
        best = steps[i];
      }
    }
    show(best);
  37. 37.🔁 What number does this code show?
    let marks = [16, 56, 66, 75, 68];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  38. 38.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Kabir", "Aman", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Zoya (c) Hi, Kabir (d) Hi, Riya
  39. 39.🔁 What number does this code show?
    let scores = [6, 20, 2];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  40. 40.🔁 What number does this code show?
    let marks = [16, 20, 4, 18, 6];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);

Answer key

  1. 22
  2. 55
  3. Hi, Aman
  4. repeats code
  5. Hi, Meera
  6. 5
  7. how many items it has
  8. 18
  9. 68
  10. 18
  11. 3
  12. 2
  13. less code to write
  14. 1
  15. Hi, Arjun
  16. 42
  17. 3
  18. 18
  19. 24
  20. Hi, Aman
  21. 40
  22. 37
  23. Hi, Zoya
  24. 2
  25. 48
  26. 15
  27. 54
  28. Hi, Kabir
  29. 43
  30. 2
  31. Hi, Aman
  32. 3
  33. 19
  34. 28
  35. Hi, Meera
  36. 19
  37. 1
  38. Hi, Zoya
  39. 28
  40. 64

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