← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 65 · 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 battery rule show?
    let battery = 86;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  2. 2.🔀 What does this PIN rule show?
    let pin = "9413";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  3. 3.🔀 What does this PIN rule show?
    let pin = "339";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  5. 5.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) save a photo (d) pick one of two actions
  6. 6.🔀 What does this sign-up rule show?
    let age = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  7. 7.🔀 What does this PIN rule show?
    let pin = "99964";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  8. 8.🔀 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
  9. 9.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  10. 10.🔀 What does this battery rule show?
    let battery = 75;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  11. 11.🔀 What does this battery rule show?
    let battery = 13;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  12. 12.🔀 What does this PIN rule show?
    let pin = "971";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 What does this battery rule show?
    let battery = 99;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  14. 14.🔀 What does this battery rule show?
    let battery = 78;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  15. 15.🔀 What does this battery rule show?
    let battery = 12;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  16. 16.🔀 What does this battery rule show?
    let battery = 15;
    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 = 350;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What does this battery rule show?
    let battery = 22;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  19. 19.🔀 With if / else if / else, how many parts run? (a) only one (b) all of them (c) none (d) two
  20. 20.🔀 What number does this shop app show?
    let total = 860;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 57;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  22. 22.🔀 What does this battery rule show?
    let battery = 98;
    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 number does this shop app show?
    let total = 690;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  25. 25.🔀 What does this battery rule show?
    let battery = 84;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 58;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  27. 27.🔀 What does this battery rule show?
    let battery = 53;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  28. 28.🔀 What does this battery rule show?
    let battery = 28;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  29. 29.🔀 What does this PIN rule show?
    let pin = "55919";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  30. 30.🔀 Which badge does this quiz app show?
    let marks = 53;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  31. 31.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) smaller or equal (d) less than
  32. 32.🔀 What does this battery rule show?
    let battery = 14;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  33. 33.🔀 Which badge does this quiz app show?
    let marks = 69;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 61;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  35. 35.🔀 What does this PIN rule show?
    let pin = "6011";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  36. 36.🔀 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
  37. 37.🔀 What does this sign-up rule show?
    let age = 9;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  38. 38.🔀 Which badge does this quiz app show?
    let marks = 46;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  39. 39.🔀 What does this PIN rule show?
    let pin = "54301";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  40. 40.🔀 Which badge does this quiz app show?
    let marks = 90;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver

Answer key

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

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