← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 19 · 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 = "12795";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  2. 2.🔀 What does this PIN rule show?
    let pin = "9388";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  3. 3.🔀 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!
  4. 4.🔀 When does the else part run? (a) always (b) when the test is false (c) never (d) when the test is true
  5. 5.🔀 What does this sign-up rule show?
    let age = 9;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  6. 6.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  7. 7.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) pick one of two actions (d) save a photo
  8. 8.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) two (d) only one
  9. 9.🔀 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!
  10. 10.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) smaller or equal (d) less than
  11. 11.🔀 What does this sign-up rule show?
    let age = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  12. 12.🔀 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!
  13. 13.🔀 What does this battery rule show?
    let battery = 75;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  14. 14.🔀 What number does this shop app show?
    let total = 290;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  15. 15.🔀 What number does this shop app show?
    let total = 360;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  16. 16.🔀 What does this battery rule show?
    let battery = 60;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  17. 17.🔀 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
  18. 18.🔀 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
  19. 19.🔀 What does this PIN rule show?
    let pin = "91859";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 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) Bronze (b) Silver (c) Gold
  21. 21.🔀 What does this battery rule show?
    let battery = 59;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  22. 22.🔀 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!
  23. 23.🔀 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) Gold (b) Silver (c) Bronze
  24. 24.🔀 What does this battery rule show?
    let battery = 52;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  25. 25.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 What does this battery rule show?
    let battery = 28;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  27. 27.🔀 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
  28. 28.🔀 What number does this shop app show?
    let total = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 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) Bronze (b) Silver (c) Gold
  30. 30.🔀 What does this battery rule show?
    let battery = 72;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 What number does this shop app show?
    let total = 410;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 37;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  33. 33.🔀 Which badge does this quiz app show?
    let marks = 93;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  34. 34.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) === (c) = (d) !==
  35. 35.🔀 What number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this battery rule show?
    let battery = 92;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  37. 37.🔀 What does this PIN rule show?
    let pin = "7234";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 What does this PIN rule show?
    let pin = "48788";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  39. 39.🔀 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
  40. 40.🔀 What does this battery rule show?
    let battery = 11;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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