← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 4 · 40 questions
TalentJR

Developer's tip (Test, then choose): if (test) { A } else { B }: A runs when the test is true, B when it is false. else if: check from the top; the first true test wins and the rest are skipped. >= includes the number itself; > does not. === tests “is equal to”.

NameDateTime takenScore ___ / 40
  1. 1.🔀 What number does this shop app show?
    let total = 850;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 What does this sign-up rule show?
    let age = 12;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  3. 3.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) not equal (d) less than
  4. 4.🔀 Which badge does this quiz app show?
    let marks = 81;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  5. 5.🔀 What does this battery rule show?
    let battery = 73;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  6. 6.🔀 When does the else part run? (a) when the test is false (b) when the test is true (c) always (d) never
  7. 7.🔀 What does this PIN rule show?
    let pin = "707";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  8. 8.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  9. 9.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  10. 10.🔀 What does this battery rule show?
    let battery = 70;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  11. 11.🔀 What number does this shop app show?
    let total = 660;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  12. 12.🔀 What does this sign-up rule show?
    let age = 11;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  13. 13.🔀 Which badge does this quiz app show?
    let marks = 83;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  14. 14.🔀 What does if / else let an app do? (a) save a photo (b) pick one of two actions (c) repeat forever (d) draw a screen
  15. 15.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  16. 16.🔀 What does this battery rule show?
    let battery = 67;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  17. 17.🔀 What number does this shop app show?
    let total = 340;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 Which badge does this quiz app show?
    let marks = 48;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  19. 19.🔀 What does this PIN rule show?
    let pin = "568";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  20. 20.🔀 What number does this shop app show?
    let total = 770;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 What number does this shop app show?
    let total = 730;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What does this battery rule show?
    let battery = 33;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  23. 23.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) => (d) !==
  24. 24.🔀 What does this battery rule show?
    let battery = 88;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  25. 25.🔀 What number does this shop app show?
    let total = 290;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 What does this PIN rule show?
    let pin = "197";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  27. 27.🔀 What does this PIN rule show?
    let pin = "9900";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 49;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  29. 29.🔀 What does this battery rule show?
    let battery = 61;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  30. 30.🔀 What does this PIN rule show?
    let pin = "7658";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  31. 31.🔀 What does this sign-up rule show?
    let age = 16;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  32. 32.🔀 What does this PIN rule show?
    let pin = "6246";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  33. 33.🔀 What does this PIN rule show?
    let pin = "131";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  34. 34.🔀 What does this sign-up rule show?
    let age = 10;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  35. 35.🔀 Which badge does this quiz app show?
    let marks = 60;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  36. 36.🔀 What does this battery rule show?
    let battery = 80;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  37. 37.🔀 What does this PIN rule show?
    let pin = "6036";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 With if / else if / else, how many parts run? (a) only one (b) all of them (c) none (d) two
  39. 39.🔀 What does this battery rule show?
    let battery = 48;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  40. 40.🔀 What does this sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!

Answer key

  1. 800
  2. Ask a parent
  3. greater than or equal
  4. Gold
  5. Battery OK
  6. when the test is false
  7. Use 4 digits
  8. 470
  9. Ask a parent
  10. Battery OK
  11. 610
  12. Ask a parent
  13. Gold
  14. pick one of two actions
  15. 510
  16. Battery OK
  17. 340
  18. Bronze
  19. Use 4 digits
  20. 720
  21. 680
  22. Battery OK
  23. ===
  24. Battery OK
  25. 290
  26. Use 4 digits
  27. PIN saved
  28. Bronze
  29. Battery OK
  30. PIN saved
  31. Welcome!
  32. PIN saved
  33. Use 4 digits
  34. Ask a parent
  35. Silver
  36. Battery OK
  37. PIN saved
  38. only one
  39. Battery OK
  40. Welcome!

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