← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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