← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 44 · 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 if / else let an app do? (a) draw a screen (b) save a photo (c) pick one of two actions (d) repeat forever
  3. 3.🔀 What does this battery rule show?
    let battery = 71;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  4. 4.🔀 What does this battery rule show?
    let battery = 42;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  5. 5.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) only one (d) none
  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 = 87;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  8. 8.🔀 What does this PIN rule show?
    let pin = "9150";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  9. 9.🔀 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) Silver (b) Bronze (c) Gold
  10. 10.🔀 What does this battery rule show?
    let battery = 55;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  11. 11.🔀 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!
  12. 12.🔀 What number does this shop app show?
    let total = 870;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 What does this battery rule show?
    let battery = 8;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  14. 14.🔀 What does this battery rule show?
    let battery = 31;
    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 = 38;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  16. 16.🔀 What does this battery rule show?
    let battery = 91;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  17. 17.🔀 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
  18. 18.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) greater than or equal (d) less than
  19. 19.🔀 What does this PIN rule show?
    let pin = "1733";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 What number does this shop app show?
    let total = 280;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 What does this PIN rule show?
    let pin = "70996";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  22. 22.🔀 What does this PIN rule show?
    let pin = "2704";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  23. 23.🔀 What does this PIN rule show?
    let pin = "3759";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  24. 24.🔀 What does this PIN rule show?
    let pin = "7804";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  25. 25.🔀 What does this battery rule show?
    let battery = 11;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 What number does this shop app show?
    let total = 600;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 What does this PIN rule show?
    let pin = "646";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  28. 28.🔀 What does this battery rule show?
    let battery = 32;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  29. 29.🔀 Which badge does this quiz app show?
    let marks = 62;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  30. 30.🔀 Which badge does this quiz app show?
    let marks = 97;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  31. 31.🔀 What number does this shop app show?
    let total = 650;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 When does the else part run? (a) never (b) when the test is false (c) when the test is true (d) always
  33. 33.🔀 What does this battery rule show?
    let battery = 67;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  34. 34.🔀 What number does this shop app show?
    let total = 790;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this PIN rule show?
    let pin = "1104";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 What does this battery rule show?
    let battery = 69;
    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) Welcome! (b) Ask a parent
  39. 39.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  40. 40.🔀 Which badge does this quiz app show?
    let marks = 43;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze

Answer key

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

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