← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 9 · 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 = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  2. 2.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) none (d) all of them
  3. 3.🔀 What number does this shop app show?
    let total = 510;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 What does this PIN rule show?
    let pin = "96558";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  5. 5.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  6. 6.🔀 What does this battery rule show?
    let battery = 61;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  7. 7.🔀 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) Gold (b) Bronze (c) Silver
  8. 8.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
  9. 9.🔀 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!
  10. 10.🔀 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) Gold (b) Silver (c) Bronze
  11. 11.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
  12. 12.🔀 What does this PIN rule show?
    let pin = "140";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  13. 13.🔀 What does this battery rule show?
    let battery = 50;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  14. 14.🔀 What does this PIN rule show?
    let pin = "168";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 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!
  16. 16.🔀 What number does this shop app show?
    let total = 870;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  17. 17.🔀 What number does this shop app show?
    let total = 260;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What does this PIN rule show?
    let pin = "162";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  19. 19.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) === (c) !== (d) =
  20. 20.🔀 What does this battery rule show?
    let battery = 14;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  21. 21.🔀 What does this PIN rule show?
    let pin = "3541";
    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 = "3364";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  23. 23.🔀 What does this PIN rule show?
    let pin = "4175";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  24. 24.🔀 What does this PIN rule show?
    let pin = "81324";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  25. 25.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 What does this PIN rule show?
    let pin = "5263";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  27. 27.🔀 What number does this shop app show?
    let total = 790;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 91;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  29. 29.🔀 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) Bronze (c) Silver
  30. 30.🔀 What number does this shop app show?
    let total = 270;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 Which badge does this quiz app show?
    let marks = 78;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  32. 32.🔀 What does this PIN rule show?
    let pin = "51086";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  33. 33.🔀 What number does this shop app show?
    let total = 680;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  34. 34.🔀 What does this PIN rule show?
    let pin = "16970";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  35. 35.🔀 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
  36. 36.🔀 What does this PIN rule show?
    let pin = "52487";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 41;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  38. 38.🔀 What does this PIN rule show?
    let pin = "201";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  39. 39.🔀 When does the else part run? (a) never (b) when the test is false (c) when the test is true (d) always
  40. 40.🔀 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

Answer key

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

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