← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 240 · 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.🔁 A loop over a list of 5 items runs its body how many times? (a) 6 (b) 5 (c) 4 (d) 1
  2. 2.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Riya", "Aman", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Zoya (b) Hi, Riya (c) Hi, Arjun (d) Hi, Aman
  3. 3.🔁 What is the LAST line this code shows?
    let names = ["Zoya", "Kabir", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Kabir (c) Hi, Zoya
  4. 4.🔁 What number does this code show?
    let marks = [19, 2, 5, 14, 16];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  5. 5.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Arjun", "Aman", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Meera (c) Hi, Riya (d) Hi, Arjun
  6. 6.🔁 What is the LAST line this code shows?
    let names = ["Meera", "Kabir", "Riya", "Arjun"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Kabir (b) Hi, Riya (c) Hi, Arjun (d) Hi, Meera
  7. 7.🔁 What number does this code show?
    let marks = [5, 18, 18];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  8. 8.🔁 What does a loop do? (a) draws icons (b) repeats code (c) deletes code (d) saves photos
  9. 9.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Meera", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Arjun (c) Hi, Aman
  10. 10.🔁 What number does this code show?
    let scores = [1, 18, 4, 15];
    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", "Meera", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Zoya (b) Hi, Kabir (c) Hi, Aman (d) Hi, Riya
  12. 12.🔁 What number does this code show?
    let runs = [16, 16, 11, 16, 9];
    let best = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] > best) {
        best = runs[i];
      }
    }
    show(best);
  13. 13.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Meera", "Arjun", "Riya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Aman (b) Hi, Riya (c) Hi, Meera (d) Hi, Arjun
  14. 14.🔁 Why use a loop to show 100 messages? (a) it hides them (b) less code to write (c) it uses more lines (d) it is slower
  15. 15.🔁 What number does this code show?
    let steps = [6, 12, 10, 2, 11];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  16. 16.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Meera", "Kabir"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Arjun (b) Hi, Kabir (c) Hi, Meera
  17. 17.🔁 What number does this code show?
    let marks = [1, 17, 6];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  18. 18.🔁 What number does this code show?
    let steps = [20, 17, 5, 4, 11];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  19. 19.🔁 What number does this code show?
    let steps = [68, 84, 66];
    let count = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] >= 40) {
        count = count + 1;
      }
    }
    show(count);
  20. 20.🔁 What number does this code show?
    let scores = [16, 68, 71];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 70) {
        count = count + 1;
      }
    }
    show(count);
  21. 21.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Kabir", "Meera", "Arjun"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Kabir (b) Hi, Meera (c) Hi, Aman (d) Hi, Arjun
  22. 22.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Riya", "Arjun", "Kabir", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Arjun (c) Hi, Riya (d) Hi, Aman
  23. 23.🔁 What number does this code show?
    let marks = [48, 78, 37];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  24. 24.🔁 What number does this code show?
    let scores = [1, 1, 14, 3, 10];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  25. 25.🔁 What number does this code show?
    let marks = [92, 51, 22];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 40) {
        count = count + 1;
      }
    }
    show(count);
  26. 26.🔁 What number does this code show?
    let steps = [4, 4, 7];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  27. 27.🔁 What number does this code show?
    let marks = [3, 5, 8];
    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 runs = [6, 14, 11, 13];
    let best = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] > best) {
        best = runs[i];
      }
    }
    show(best);
  29. 29.🔁 What number does this code show?
    let scores = [6, 5, 12, 6];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  30. 30.🔁 list.length tells you ___. (a) the first item (b) the last item (c) how many items it has (d) the biggest item
  31. 31.🔁 What number does this code show?
    let runs = [39, 37, 37, 46, 23];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 40) {
        count = count + 1;
      }
    }
    show(count);
  32. 32.🔁 What number does this code show?
    let scores = [3, 5, 10];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  33. 33.🔁 What number does this code show?
    let steps = [19, 14, 15];
    let best = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] > best) {
        best = steps[i];
      }
    }
    show(best);
  34. 34.🔁 In for (let i = 0; i < 3; i++), which values does i take? (a) 0, 1, 2, 3 (b) 3 (c) 0, 1, 2 (d) 1, 2, 3
  35. 35.🔁 What number does this code show?
    let marks = [8, 18, 20];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  36. 36.🔁 What number does this code show?
    let marks = [40, 23, 87];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  37. 37.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Zoya", "Riya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Zoya (c) Hi, Aman
  38. 38.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Aman", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Aman (c) Hi, Zoya
  39. 39.🔁 What number does this code show?
    let marks = [11, 16, 6, 3, 3];
    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 scores = [70, 44, 69];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);

Answer key

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

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