← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 31 · 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 = "671";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  2. 2.🔀 When does the else part run? (a) when the test is false (b) always (c) when the test is true (d) never
  3. 3.🔀 Which badge does this quiz app show?
    let marks = 27;
    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 = 11;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  5. 5.🔀 What does this battery rule show?
    let battery = 80;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  6. 6.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) repeat forever (d) draw a screen
  7. 7.🔀 What does this battery rule show?
    let battery = 40;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  8. 8.🔀 What does this PIN rule show?
    let pin = "13305";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  9. 9.🔀 Which badge does this quiz app show?
    let marks = 84;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  10. 10.🔀 What does this PIN rule show?
    let pin = "5820";
    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 = 86;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  12. 12.🔀 Which badge does this quiz app show?
    let marks = 35;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  13. 13.🔀 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) Gold (b) Bronze (c) Silver
  14. 14.🔀 What does this PIN rule show?
    let pin = "29599";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) none (d) only one
  16. 16.🔀 Which badge does this quiz app show?
    let marks = 26;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  17. 17.🔀 What does this battery rule show?
    let battery = 28;
    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 = "4011";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  19. 19.🔀 What does this PIN rule show?
    let pin = "22675";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) less than (d) smaller or equal
  21. 21.🔀 What does this PIN rule show?
    let pin = "415";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  22. 22.🔀 What number does this shop app show?
    let total = 730;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  23. 23.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) === (c) = (d) !==
  24. 24.🔀 Which badge does this quiz app show?
    let marks = 70;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  25. 25.🔀 What does this PIN rule show?
    let pin = "45923";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 What does this battery rule show?
    let battery = 96;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  27. 27.🔀 What does this PIN rule show?
    let pin = "5459";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  28. 28.🔀 What does this PIN rule show?
    let pin = "45588";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  29. 29.🔀 Which badge does this quiz app show?
    let marks = 54;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  30. 30.🔀 Which badge does this quiz app show?
    let marks = 72;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  31. 31.🔀 What does this battery rule show?
    let battery = 5;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  32. 32.🔀 What does this PIN rule show?
    let pin = "908";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  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 does this battery rule show?
    let battery = 31;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  35. 35.🔀 What number does this shop app show?
    let total = 710;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What number does this shop app show?
    let total = 680;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 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) Bronze (c) Silver
  38. 38.🔀 What does this battery rule show?
    let battery = 82;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  39. 39.🔀 What does this battery rule show?
    let battery = 14;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  40. 40.🔀 What does this battery rule show?
    let battery = 1;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery

Answer key

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

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