← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 18 · 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 number does this shop app show?
    let total = 790;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 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!
  3. 3.🔀 What number does this shop app show?
    let total = 410;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 What does this PIN rule show?
    let pin = "1802";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  5. 5.🔀 What number does this shop app show?
    let total = 430;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  6. 6.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) none (d) only one
  7. 7.🔀 What does this PIN rule show?
    let pin = "471";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  8. 8.🔀 What does this sign-up rule show?
    let age = 16;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  9. 9.🔀 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
  10. 10.🔀 What does this battery rule show?
    let battery = 59;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  11. 11.🔀 Which badge does this quiz app show?
    let marks = 79;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  12. 12.🔀 What does this PIN rule show?
    let pin = "798";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 Which badge does this quiz app show?
    let marks = 83;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  14. 14.🔀 What does >= mean? (a) less than (b) smaller or equal (c) greater than or equal (d) not equal
  15. 15.🔀 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
  16. 16.🔀 What does this PIN rule show?
    let pin = "18570";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  17. 17.🔀 What does this PIN rule show?
    let pin = "529";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  18. 18.🔀 Which badge does this quiz app show?
    let marks = 57;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  19. 19.🔀 What does this sign-up rule show?
    let age = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  20. 20.🔀 What does this battery rule show?
    let battery = 17;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  21. 21.🔀 What does this battery rule show?
    let battery = 56;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  22. 22.🔀 What does this battery rule show?
    let battery = 93;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  23. 23.🔀 What does this PIN rule show?
    let pin = "27586";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  24. 24.🔀 What does this battery rule show?
    let battery = 64;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  25. 25.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 What does this PIN rule show?
    let pin = "9274";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  27. 27.🔀 What does this PIN rule show?
    let pin = "181";
    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 = 34;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  29. 29.🔀 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!
  30. 30.🔀 What does if / else let an app do? (a) draw a screen (b) pick one of two actions (c) repeat forever (d) save a photo
  31. 31.🔀 What number does this shop app show?
    let total = 880;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does this battery rule show?
    let battery = 2;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) = (c) => (d) !==
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 68;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  35. 35.🔀 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!
  36. 36.🔀 What does this PIN rule show?
    let pin = "481";
    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 = 66;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  38. 38.🔀 Which badge does this quiz app show?
    let marks = 95;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  39. 39.🔀 What does this PIN rule show?
    let pin = "486";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  40. 40.🔀 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

Answer key

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

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