← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 43 · 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 = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  2. 2.🔀 What does >= mean? (a) greater than or equal (b) less than (c) not equal (d) smaller or equal
  3. 3.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) two (d) all of them
  4. 4.🔀 What does this PIN rule show?
    let pin = "2514";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  5. 5.🔀 Which badge does this quiz app show?
    let marks = 42;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  6. 6.🔀 What does this battery rule show?
    let battery = 79;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  7. 7.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) !== (c) === (d) =
  8. 8.🔀 What number does this shop app show?
    let total = 370;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  9. 9.🔀 What does this PIN rule show?
    let pin = "834";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  10. 10.🔀 What does this PIN rule show?
    let pin = "348";
    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 = 23;
    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 = "4137";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 What does this PIN rule show?
    let pin = "49867";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  14. 14.🔀 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
  15. 15.🔀 Which badge does this quiz app show?
    let marks = 33;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  16. 16.🔀 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) Silver (c) Gold
  17. 17.🔀 What number does this shop app show?
    let total = 530;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What does this battery rule show?
    let battery = 63;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  19. 19.🔀 What number does this shop app show?
    let total = 440;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 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!
  21. 21.🔀 What number does this shop app show?
    let total = 260;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What does this PIN rule show?
    let pin = "1970";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  23. 23.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) pick one of two actions (d) draw a screen
  24. 24.🔀 What does this PIN rule show?
    let pin = "4666";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  25. 25.🔀 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
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 94;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  27. 27.🔀 Which badge does this quiz app show?
    let marks = 30;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 60;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  29. 29.🔀 What number does this shop app show?
    let total = 840;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  30. 30.🔀 What does this battery rule show?
    let battery = 16;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 What does this battery rule show?
    let battery = 97;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  32. 32.🔀 What does this battery rule show?
    let battery = 58;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 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) Gold (c) Silver
  34. 34.🔀 What number does this shop app show?
    let total = 760;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 When does the else part run? (a) always (b) when the test is false (c) when the test is true (d) never
  36. 36.🔀 What does this PIN rule show?
    let pin = "601";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  37. 37.🔀 What does this battery rule show?
    let battery = 75;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  38. 38.🔀 What does this sign-up rule show?
    let age = 12;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  39. 39.🔀 What number does this shop app show?
    let total = 820;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 What does this battery rule show?
    let battery = 84;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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