← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 54 · 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.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) === (d) !==
  2. 2.🔀 What does this PIN rule show?
    let pin = "15518";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  3. 3.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) two (d) none
  4. 4.🔀 What does this PIN rule show?
    let pin = "1332";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  5. 5.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
  6. 6.🔀 What does this battery rule show?
    let battery = 66;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  7. 7.🔀 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
  8. 8.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) repeat forever (d) pick one of two actions
  9. 9.🔀 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!
  10. 10.🔀 What does this battery rule show?
    let battery = 26;
    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 = 21;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  12. 12.🔀 Which badge does this quiz app show?
    let marks = 84;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  13. 13.🔀 What number does this shop app show?
    let total = 410;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 What does this PIN rule show?
    let pin = "5382";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 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!
  16. 16.🔀 What number does this shop app show?
    let total = 640;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  17. 17.🔀 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!
  18. 18.🔀 Which badge does this quiz app show?
    let marks = 33;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  19. 19.🔀 What does this battery rule show?
    let battery = 18;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  20. 20.🔀 Which badge does this quiz app show?
    let marks = 42;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  21. 21.🔀 What number does this shop app show?
    let total = 480;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  23. 23.🔀 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!
  24. 24.🔀 What does this PIN rule show?
    let pin = "67120";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  25. 25.🔀 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
  26. 26.🔀 What does this battery rule show?
    let battery = 72;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  27. 27.🔀 What number does this shop app show?
    let total = 280;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What does this battery rule show?
    let battery = 89;
    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 = 760;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  30. 30.🔀 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
  31. 31.🔀 What does this PIN rule show?
    let pin = "72386";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  32. 32.🔀 What does this battery rule show?
    let battery = 87;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  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) Bronze (b) Silver (c) Gold
  34. 34.🔀 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!
  35. 35.🔀 What number does this shop app show?
    let total = 340;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this battery rule show?
    let battery = 29;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  37. 37.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  38. 38.🔀 What does this battery rule show?
    let battery = 88;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  39. 39.🔀 What does this PIN rule show?
    let pin = "489";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  40. 40.🔀 What does this PIN rule show?
    let pin = "66850";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

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

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