← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

App development lesson 19: Loops over lists · Set 153 · 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) 5 (b) 4 (c) 6 (d) 1
  2. 2.🔁 What number does this code show?
    let steps = [4, 15, 12, 9];
    let best = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] > best) {
        best = steps[i];
      }
    }
    show(best);
  3. 3.🔁 What does a loop do? (a) saves photos (b) repeats code (c) draws icons (d) deletes code
  4. 4.🔁 What is the LAST line this code shows?
    let names = ["Kabir", "Aman", "Arjun", "Meera", "Riya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Arjun (c) Hi, Aman (d) Hi, Kabir
  5. 5.🔁 What is the LAST line this code shows?
    let names = ["Kabir", "Meera", "Riya", "Aman", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Zoya (c) Hi, Riya (d) Hi, Kabir
  6. 6.🔁 What is the LAST line this code shows?
    let names = ["Kabir", "Meera", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Kabir (c) Hi, Zoya
  7. 7.🔁 What number does this code show?
    let marks = [11, 12, 18, 11];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  8. 8.🔁 What number does this code show?
    let runs = [15, 7, 19, 9, 8];
    let best = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] > best) {
        best = runs[i];
      }
    }
    show(best);
  9. 9.🔁 What number does this code show?
    let marks = [17, 9, 11];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  10. 10.🔁 What number does this code show?
    let steps = [20, 16, 5, 1];
    let total = 0;
    for (let i = 0; i < steps.length; i++) {
      total = total + steps[i];
    }
    show(total);
  11. 11.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Kabir", "Riya", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Aman (c) Hi, Riya (d) Hi, Kabir
  12. 12.🔁 What number does this code show?
    let marks = [13, 8, 14, 11, 20];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  13. 13.🔁 What number does this code show?
    let scores = [1, 5, 11, 4];
    let best = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] > best) {
        best = scores[i];
      }
    }
    show(best);
  14. 14.🔁 What number does this code show?
    let scores = [19, 1, 19, 17];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  15. 15.🔁 What number does this code show?
    let runs = [11, 19, 3, 14, 17];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  16. 16.🔁 In for (let i = 0; i < 3; i++), which values does i take? (a) 0, 1, 2, 3 (b) 1, 2, 3 (c) 3 (d) 0, 1, 2
  17. 17.🔁 What number does this code show?
    let scores = [9, 11, 17, 8, 5];
    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 marks = [13, 8, 12, 15];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  19. 19.🔁 What number does this code show?
    let runs = [20, 10, 8];
    let total = 0;
    for (let i = 0; i < runs.length; i++) {
      total = total + runs[i];
    }
    show(total);
  20. 20.🔁 What number does this code show?
    let runs = [64, 13, 33];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  21. 21.🔁 What number does this code show?
    let marks = [11, 89, 79, 39];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 60) {
        count = count + 1;
      }
    }
    show(count);
  22. 22.🔁 What number does this code show?
    let marks = [6, 18, 2];
    let best = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] > best) {
        best = marks[i];
      }
    }
    show(best);
  23. 23.🔁 What is the LAST line this code shows?
    let names = ["Arjun", "Riya", "Zoya"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Arjun (c) Hi, Zoya
  24. 24.🔁 Why use a loop to show 100 messages? (a) it uses more lines (b) less code to write (c) it hides them (d) it is slower
  25. 25.🔁 What is the LAST line this code shows?
    let names = ["Zoya", "Aman", "Arjun"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Arjun (b) Hi, Zoya (c) Hi, Aman
  26. 26.🔁 What number does this code show?
    let marks = [13, 18, 15];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  27. 27.🔁 What is the LAST line this code shows?
    let names = ["Meera", "Arjun", "Zoya", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Arjun (c) Hi, Aman (d) Hi, Zoya
  28. 28.🔁 What number does this code show?
    let runs = [33, 26, 11, 59];
    let count = 0;
    for (let i = 0; i < runs.length; i++) {
      if (runs[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  29. 29.🔁 What number does this code show?
    let scores = [14, 15, 9, 10];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  30. 30.🔁 What number does this code show?
    let marks = [5, 14, 1];
    let total = 0;
    for (let i = 0; i < marks.length; i++) {
      total = total + marks[i];
    }
    show(total);
  31. 31.🔁 What number does this code show?
    let scores = [78, 77, 82, 67, 23];
    let count = 0;
    for (let i = 0; i < scores.length; i++) {
      if (scores[i] >= 50) {
        count = count + 1;
      }
    }
    show(count);
  32. 32.🔁 What number does this code show?
    let runs = [18, 9, 10, 15, 6];
    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 steps = [5, 5, 20];
    let best = 0;
    for (let i = 0; i < steps.length; i++) {
      if (steps[i] > best) {
        best = steps[i];
      }
    }
    show(best);
  34. 34.🔁 What is the LAST line this code shows?
    let names = ["Zoya", "Riya", "Kabir", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Riya (b) Hi, Kabir (c) Hi, Zoya (d) Hi, Aman
  35. 35.🔁 What is the LAST line this code shows?
    let names = ["Meera", "Riya", "Aman"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Riya (c) Hi, Aman
  36. 36.🔁 What number does this code show?
    let scores = [7, 9, 6];
    let total = 0;
    for (let i = 0; i < scores.length; i++) {
      total = total + scores[i];
    }
    show(total);
  37. 37.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Riya", "Zoya", "Kabir"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Kabir (b) Hi, Zoya (c) Hi, Aman (d) Hi, Riya
  38. 38.🔁 What is the LAST line this code shows?
    let names = ["Riya", "Meera", "Kabir"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Kabir (c) Hi, Riya
  39. 39.🔁 What number does this code show?
    let marks = [84, 52, 31];
    let count = 0;
    for (let i = 0; i < marks.length; i++) {
      if (marks[i] >= 40) {
        count = count + 1;
      }
    }
    show(count);
  40. 40.🔁 What is the LAST line this code shows?
    let names = ["Aman", "Zoya", "Meera"];
    for (let i = 0; i < names.length; i++) {
      show("Hi, " + names[i]);
    }
    (a) Hi, Meera (b) Hi, Zoya (c) Hi, Aman

Answer key

  1. 5
  2. 15
  3. repeats code
  4. Hi, Riya
  5. Hi, Zoya
  6. Hi, Zoya
  7. 52
  8. 19
  9. 17
  10. 42
  11. Hi, Meera
  12. 66
  13. 11
  14. 56
  15. 64
  16. 0, 1, 2
  17. 50
  18. 15
  19. 38
  20. 1
  21. 2
  22. 18
  23. Hi, Zoya
  24. less code to write
  25. Hi, Arjun
  26. 46
  27. Hi, Aman
  28. 1
  29. 48
  30. 20
  31. 4
  32. 58
  33. 20
  34. Hi, Aman
  35. Hi, Aman
  36. 22
  37. Hi, Kabir
  38. Hi, Kabir
  39. 2
  40. Hi, Meera

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