← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 148 · 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.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) only one (d) all of them
  2. 2.🔀 What does this PIN rule show?
    let pin = "377";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  3. 3.🔀 What does this battery rule show?
    let battery = 68;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  4. 4.🔀 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) Gold (b) Bronze (c) Silver
  5. 5.🔀 What does this PIN rule show?
    let pin = "245";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  6. 6.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) => (c) === (d) =
  7. 7.🔀 Which badge does this quiz app show?
    let marks = 38;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  8. 8.🔀 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
  9. 9.🔀 What number does this shop app show?
    let total = 770;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  10. 10.🔀 What number does this shop app show?
    let total = 590;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  11. 11.🔀 What does this PIN rule show?
    let pin = "6432";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  12. 12.🔀 What number does this shop app show?
    let total = 660;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 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
  14. 14.🔀 What does if / else let an app do? (a) repeat forever (b) pick one of two actions (c) draw a screen (d) save a photo
  15. 15.🔀 What number does this shop app show?
    let total = 430;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  16. 16.🔀 What does this PIN rule show?
    let pin = "15776";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  17. 17.🔀 What does this sign-up rule show?
    let age = 10;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  18. 18.🔀 What does this PIN rule show?
    let pin = "5679";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  19. 19.🔀 What does this battery rule show?
    let battery = 21;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  20. 20.🔀 What number does this shop app show?
    let total = 620;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 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
  22. 22.🔀 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!
  23. 23.🔀 What does >= mean? (a) less than (b) smaller or equal (c) greater than or equal (d) not equal
  24. 24.🔀 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!
  25. 25.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 98;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  27. 27.🔀 What does this PIN rule show?
    let pin = "6166";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  28. 28.🔀 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
  29. 29.🔀 What does this battery rule show?
    let battery = 22;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  30. 30.🔀 What does this PIN rule show?
    let pin = "25043";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  31. 31.🔀 What does this PIN rule show?
    let pin = "46623";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  32. 32.🔀 What does this PIN rule show?
    let pin = "76969";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  33. 33.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  34. 34.🔀 What number does this shop app show?
    let total = 730;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 What does this PIN rule show?
    let pin = "47502";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  36. 36.🔀 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) Silver (b) Bronze (c) Gold
  37. 37.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) always (d) never
  38. 38.🔀 What does this PIN rule show?
    let pin = "9209";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  39. 39.🔀 What does this battery rule show?
    let battery = 89;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  40. 40.🔀 What number does this shop app show?
    let total = 460;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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