← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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