← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 49 · 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 battery rule show?
    let battery = 39;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  2. 2.🔀 What does this PIN rule show?
    let pin = "56367";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  3. 3.🔀 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!
  4. 4.🔀 What number does this shop app show?
    let total = 840;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  5. 5.🔀 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
  6. 6.🔀 What does this battery rule show?
    let battery = 79;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  7. 7.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) two (d) only one
  8. 8.🔀 Which badge does this quiz app show?
    let marks = 28;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  9. 9.🔀 What does this PIN rule show?
    let pin = "113";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  10. 10.🔀 Which badge does this quiz app show?
    let marks = 47;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  11. 11.🔀 What number does this shop app show?
    let total = 850;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  12. 12.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) !== (c) => (d) =
  13. 13.🔀 What does this PIN rule show?
    let pin = "238";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  14. 14.🔀 What does >= mean? (a) less than (b) greater than or equal (c) not equal (d) smaller or equal
  15. 15.🔀 What does this battery rule show?
    let battery = 68;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  16. 16.🔀 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
  17. 17.🔀 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
  18. 18.🔀 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!
  19. 19.🔀 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!
  20. 20.🔀 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
  21. 21.🔀 What number does this shop app show?
    let total = 680;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 Which badge does this quiz app show?
    let marks = 21;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  23. 23.🔀 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
  24. 24.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
  25. 25.🔀 What does this battery rule show?
    let battery = 16;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 What does if / else let an app do? (a) pick one of two actions (b) draw a screen (c) save a photo (d) repeat forever
  27. 27.🔀 What number does this shop app show?
    let total = 330;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 36;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  29. 29.🔀 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
  30. 30.🔀 What does this battery rule show?
    let battery = 97;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 What does this battery rule show?
    let battery = 12;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  32. 32.🔀 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!
  33. 33.🔀 What does this PIN rule show?
    let pin = "959";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  34. 34.🔀 What does this PIN rule show?
    let pin = "2378";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  35. 35.🔀 Which badge does this quiz app show?
    let marks = 94;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  36. 36.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 What number does this shop app show?
    let total = 520;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 What number does this shop app show?
    let total = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 What number does this shop app show?
    let total = 200;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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