← Loops over lists lesson New set →

App Dev Worksheet: Loops over Lists

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

Answer key

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

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