← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 418 · 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 runs = [1, 12, 16, 10];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  2. 2.🔁 What number does this code show?
    let steps = [3, 13, 13];
    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 = [29, 45, 54, 34];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  4. 4.🔁 What number does this code show?
    let steps = [86, 15, 93, 61];
    let count = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  5. 5.🔁 What number does this code show?
    let scores = [20, 8, 7, 16];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  6. 6.🔁 What number does this code show?
    let steps = [19, 38, 72, 70, 25];
    let count = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  7. 7.🔁 What number does this code show?
    let scores = [5, 17, 17, 10, 18];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  8. 8.🔁 What number does this code show?
    let marks = [1, 17, 12];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  9. 9.🔁 What number does this code show?
    let steps = [8, 12, 9];
    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 = ["Riya", "Zoya", "Kabir", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Kabir (c) Hi, Aman (d) Hi, Zoya
  11. 11.🔁 What number does this code show?
    let marks = [1, 11, 6, 9, 13];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  12. 12.🔁 What number does this code show?
    let runs = [28, 59, 18];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 40) {
        count = count + 1;
      }
    }
    show(count);
  13. 13.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Kabir", "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, Kabir
  14. 14.🔁 What number does this code show?
    let runs = [62, 26, 75, 36, 12];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  15. 15.🔁 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
  16. 16.🔁 What number does this code show?
    let scores = [2, 6, 3, 13, 3];
    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 = ["Arjun", "Meera", "Riya", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Aman (c) Hi, Meera (d) Hi, Arjun
  18. 18.🔁 What is the LAST line this code shows?
    let names = ["Meera", "Zoya", "Aman", "Riya", "Arjun"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Zoya (b) Hi, Aman (c) Hi, Meera (d) Hi, Arjun
  19. 19.🔁 What number does this code show?
    let steps = [30, 10, 83, 72];
    let count = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  20. 20.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Riya", "Zoya", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Aman (c) Hi, Meera (d) Hi, Zoya
  21. 21.🔁 What number does this code show?
    let runs = [93, 11, 99, 81, 49];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  22. 22.🔁 list.length tells you ___. (a) how many items it has (b) the last item (c) the first item (d) the biggest item
  23. 23.🔁 What number does this code show?
    let scores = [48, 24, 41];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  24. 24.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Aman", "Riya", "Kabir", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Arjun (b) Hi, Riya (c) Hi, Aman (d) Hi, Zoya
  25. 25.🔁 What number does this code show?
    let runs = [85, 96, 42, 13];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  26. 26.🔁 What number does this code show?
    let runs = [10, 19, 10];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  27. 27.🔁 What number does this code show?
    let marks = [10, 17, 14];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  28. 28.🔁 What number does this code show?
    let scores = [6, 1, 3, 7, 10];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  29. 29.🔁 What number does this code show?
    let steps = [98, 78, 15, 88, 92];
    let count = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  30. 30.🔁 What number does this code show?
    let runs = [13, 12, 20, 2, 20];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  31. 31.🔁 What number does this code show?
    let marks = [6, 6, 2, 3, 4];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  32. 32.🔁 What number does this code show?
    let scores = [2, 18, 6, 14, 4];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  33. 33.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Meera", "Arjun", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Arjun (c) Hi, Zoya (d) Hi, Aman
  34. 34.🔁 What number does this code show?
    let scores = [10, 16, 5];
    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 = [7, 16, 18];
    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 = [2, 9, 11, 1];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  37. 37.🔁 In for (let i = 0; i < 3; i++), which values does i take? (a) 3 (b) 0, 1, 2 (c) 0, 1, 2, 3 (d) 1, 2, 3
  38. 38.🔁 What number does this code show?
    let marks = [4, 17, 4, 2];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  39. 39.🔁 What number does this code show?
    let marks = [12, 3, 3, 9, 13];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  40. 40.🔁 What number does this code show?
    let steps = [10, 2, 5, 11, 12];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);

Answer key

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

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