← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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