← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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