← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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