← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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