← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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