← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 63 · 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 = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  2. 2.🔀 What does this battery rule show?
    let battery = 54;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  3. 3.🔀 Which badge does this quiz app show?
    let marks = 88;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  4. 4.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) !== (d) =
  5. 5.🔀 What does >= mean? (a) less than (b) not equal (c) smaller or equal (d) greater than or equal
  6. 6.🔀 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) Bronze (b) Silver (c) Gold
  7. 7.🔀 Which badge does this quiz app show?
    let marks = 40;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  8. 8.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) only one (d) none
  9. 9.🔀 What does this PIN rule show?
    let pin = "5817";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  10. 10.🔀 What does this sign-up rule show?
    let age = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  11. 11.🔀 What does this battery rule show?
    let battery = 82;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  12. 12.🔀 Which badge does this quiz app show?
    let marks = 22;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  13. 13.🔀 What does this battery rule show?
    let battery = 62;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  14. 14.🔀 What does this battery rule show?
    let battery = 37;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  15. 15.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) pick one of two actions (d) save a photo
  16. 16.🔀 When does the else part run? (a) when the test is true (b) always (c) never (d) when the test is false
  17. 17.🔀 What does this battery rule show?
    let battery = 21;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  18. 18.🔀 What does this PIN rule show?
    let pin = "4110";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  19. 19.🔀 What number does this shop app show?
    let total = 630;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 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) Silver (b) Bronze (c) Gold
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 76;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  22. 22.🔀 What number does this shop app show?
    let total = 750;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  23. 23.🔀 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
  24. 24.🔀 What does this PIN rule show?
    let pin = "697";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  25. 25.🔀 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) Gold (c) Silver
  26. 26.🔀 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
  27. 27.🔀 What number does this shop app show?
    let total = 640;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What does this PIN rule show?
    let pin = "49260";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  29. 29.🔀 What number does this shop app show?
    let total = 720;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  30. 30.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 What number does this shop app show?
    let total = 530;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does this PIN rule show?
    let pin = "4912";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  33. 33.🔀 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
  34. 34.🔀 What does this PIN rule show?
    let pin = "73817";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  35. 35.🔀 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!
  36. 36.🔀 What does this battery rule show?
    let battery = 30;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  37. 37.🔀 What does this battery rule show?
    let battery = 41;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  38. 38.🔀 What number does this shop app show?
    let total = 270;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 What does this PIN rule show?
    let pin = "35379";
    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 = 570;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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