← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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