← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

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

Answer key

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

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