← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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