← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 15 · 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 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
  2. 2.🔀 What does this PIN rule show?
    let pin = "295";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  3. 3.🔀 What number does this shop app show?
    let total = 830;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 Which badge does this quiz app show?
    let marks = 75;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  5. 5.🔀 Which badge does this quiz app show?
    let marks = 26;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  6. 6.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) === (d) !==
  7. 7.🔀 What does this battery rule show?
    let battery = 62;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  8. 8.🔀 What number does this shop app show?
    let total = 230;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  9. 9.🔀 What does this sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  10. 10.🔀 What does this PIN rule show?
    let pin = "28991";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  11. 11.🔀 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
  12. 12.🔀 What does this sign-up rule show?
    let age = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  13. 13.🔀 What number does this shop app show?
    let total = 690;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 What does >= mean? (a) less than (b) not equal (c) greater than or equal (d) smaller or equal
  15. 15.🔀 What does this battery rule show?
    let battery = 49;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  16. 16.🔀 Which badge does this quiz app show?
    let marks = 66;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  17. 17.🔀 What number does this shop app show?
    let total = 480;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What does this sign-up rule show?
    let age = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  19. 19.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) only one (d) all of them
  21. 21.🔀 What does if / else let an app do? (a) draw a screen (b) pick one of two actions (c) repeat forever (d) save a photo
  22. 22.🔀 What does this PIN rule show?
    let pin = "825";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  23. 23.🔀 What does this battery rule show?
    let battery = 77;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  24. 24.🔀 What does this battery rule show?
    let battery = 40;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  25. 25.🔀 What does this PIN rule show?
    let pin = "7791";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 What does this battery rule show?
    let battery = 81;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  27. 27.🔀 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!
  28. 28.🔀 What number does this shop app show?
    let total = 260;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 Which badge does this quiz app show?
    let marks = 29;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  30. 30.🔀 Which badge does this quiz app show?
    let marks = 82;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  31. 31.🔀 What does this battery rule show?
    let battery = 92;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 37;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  33. 33.🔀 Which badge does this quiz app show?
    let marks = 35;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  34. 34.🔀 What number does this shop app show?
    let total = 710;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 What does this battery rule show?
    let battery = 44;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  36. 36.🔀 Which badge does this quiz app show?
    let marks = 28;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  37. 37.🔀 What does this PIN rule show?
    let pin = "927";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  38. 38.🔀 What number does this shop app show?
    let total = 780;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 What does this battery rule show?
    let battery = 89;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  40. 40.🔀 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) Gold (b) Silver (c) Bronze

Answer key

  1. Welcome!
  2. Use 4 digits
  3. 780
  4. Silver
  5. Bronze
  6. ===
  7. Battery OK
  8. 230
  9. Welcome!
  10. Use 4 digits
  11. Battery OK
  12. Welcome!
  13. 640
  14. greater than or equal
  15. Battery OK
  16. Silver
  17. 480
  18. Welcome!
  19. 240
  20. only one
  21. pick one of two actions
  22. Use 4 digits
  23. Battery OK
  24. Battery OK
  25. PIN saved
  26. Battery OK
  27. Ask a parent
  28. 260
  29. Bronze
  30. Gold
  31. Battery OK
  32. Bronze
  33. Bronze
  34. 660
  35. Battery OK
  36. Bronze
  37. Use 4 digits
  38. 730
  39. Battery OK
  40. Gold

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