← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 36 · 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 PIN rule show?
    let pin = "9278";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  2. 2.🔀 What does >= mean? (a) greater than or equal (b) smaller or equal (c) less than (d) not equal
  3. 3.🔀 Which badge does this quiz app show?
    let marks = 36;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  4. 4.🔀 What does this sign-up rule show?
    let age = 16;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  5. 5.🔀 Which badge does this quiz app show?
    let marks = 68;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  6. 6.🔀 Which badge does this quiz app show?
    let marks = 86;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  7. 7.🔀 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
  8. 8.🔀 What does this battery rule show?
    let battery = 52;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  9. 9.🔀 What does this battery rule show?
    let battery = 31;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  10. 10.🔀 What does this PIN rule show?
    let pin = "33118";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  11. 11.🔀 What does this battery rule show?
    let battery = 83;
    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 = "70346";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 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!
  14. 14.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  15. 15.🔀 What does this PIN rule show?
    let pin = "98766";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  16. 16.🔀 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
  17. 17.🔀 What does this battery rule show?
    let battery = 12;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  18. 18.🔀 What does if / else let an app do? (a) repeat forever (b) draw a screen (c) save a photo (d) pick one of two actions
  19. 19.🔀 What does this PIN rule show?
    let pin = "703";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 What does this battery rule show?
    let battery = 54;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  21. 21.🔀 What does this PIN rule show?
    let pin = "4521";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  22. 22.🔀 Which badge does this quiz app show?
    let marks = 89;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  23. 23.🔀 What does this battery rule show?
    let battery = 7;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  24. 24.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) === (c) => (d) =
  25. 25.🔀 What number does this shop app show?
    let total = 250;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 What does this battery rule show?
    let battery = 93;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 100;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  29. 29.🔀 What does this battery rule show?
    let battery = 16;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  30. 30.🔀 When does the else part run? (a) when the test is false (b) when the test is true (c) never (d) always
  31. 31.🔀 What does this sign-up rule show?
    let age = 11;
    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 = "75951";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  33. 33.🔀 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) Gold (b) Bronze (c) Silver
  34. 34.🔀 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
  35. 35.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) two (d) none
  36. 36.🔀 What number does this shop app show?
    let total = 360;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 91;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  38. 38.🔀 What does this PIN rule show?
    let pin = "8648";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  39. 39.🔀 What does this PIN rule show?
    let pin = "5773";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  40. 40.🔀 What number does this shop app show?
    let total = 270;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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