← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 3 · 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 = "9664";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  2. 2.🔀 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!
  3. 3.🔀 What does if / else let an app do? (a) save a photo (b) draw a screen (c) pick one of two actions (d) repeat forever
  4. 4.🔀 What does >= mean? (a) greater than or equal (b) not equal (c) less than (d) smaller or equal
  5. 5.🔀 What number does this shop app show?
    let total = 420;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  6. 6.🔀 What does this battery rule show?
    let battery = 9;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  7. 7.🔀 What number does this shop app show?
    let total = 430;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 What does this battery rule show?
    let battery = 13;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  9. 9.🔀 What does this battery rule show?
    let battery = 19;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  10. 10.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) !== (d) ===
  11. 11.🔀 When does the else part run? (a) when the test is false (b) never (c) always (d) when the test is true
  12. 12.🔀 What does this PIN rule show?
    let pin = "620";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 What number does this shop app show?
    let total = 460;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 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!
  15. 15.🔀 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) Gold (b) Silver (c) Bronze
  16. 16.🔀 What does this battery rule show?
    let battery = 10;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  17. 17.🔀 What does this PIN rule show?
    let pin = "269";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  18. 18.🔀 What number does this shop app show?
    let total = 640;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  19. 19.🔀 What does this PIN rule show?
    let pin = "990";
    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 = 37;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  21. 21.🔀 What number does this shop app show?
    let total = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What does this battery rule show?
    let battery = 7;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  23. 23.🔀 What does this sign-up rule show?
    let age = 16;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  24. 24.🔀 Which badge does this quiz app show?
    let marks = 40;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  25. 25.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 46;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  27. 27.🔀 What does this PIN rule show?
    let pin = "2653";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 32;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  29. 29.🔀 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) Silver (b) Bronze (c) Gold
  30. 30.🔀 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!
  31. 31.🔀 What does this PIN rule show?
    let pin = "804";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  32. 32.🔀 What does this PIN rule show?
    let pin = "5854";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  33. 33.🔀 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
  34. 34.🔀 What number does this shop app show?
    let total = 330;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 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
  36. 36.🔀 Which badge does this quiz app show?
    let marks = 48;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  37. 37.🔀 What number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 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) Gold (c) Silver
  39. 39.🔀 What does this sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  40. 40.🔀 What does this battery rule show?
    let battery = 84;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery

Answer key

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

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