← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 47 · 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 = "168";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  2. 2.🔀 Which badge does this quiz app show?
    let marks = 45;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  3. 3.🔀 What does this battery rule show?
    let battery = 43;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  4. 4.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) === (c) => (d) =
  5. 5.🔀 What does this battery rule show?
    let battery = 74;
    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 = 60;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  7. 7.🔀 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!
  8. 8.🔀 Which badge does this quiz app show?
    let marks = 20;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  9. 9.🔀 What does this battery rule show?
    let battery = 77;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  10. 10.🔀 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) Silver (b) Bronze (c) Gold
  11. 11.🔀 What number does this shop app show?
    let total = 220;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  12. 12.🔀 What does this PIN rule show?
    let pin = "258";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  13. 13.🔀 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
  14. 14.🔀 What does this PIN rule show?
    let pin = "4642";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  15. 15.🔀 What does this battery rule show?
    let battery = 27;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  16. 16.🔀 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
  17. 17.🔀 What does this battery rule show?
    let battery = 88;
    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 = 12;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  19. 19.🔀 Which badge does this quiz app show?
    let marks = 23;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  20. 20.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 What does this PIN rule show?
    let pin = "812";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  22. 22.🔀 What number does this shop app show?
    let total = 480;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  23. 23.🔀 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!
  24. 24.🔀 What does this PIN rule show?
    let pin = "497";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  25. 25.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) none (d) only one
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 99;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  27. 27.🔀 What does this PIN rule show?
    let pin = "106";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  28. 28.🔀 What does this PIN rule show?
    let pin = "403";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  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 number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 35;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  33. 33.🔀 What does this battery rule show?
    let battery = 23;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  34. 34.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) not equal (d) less than
  35. 35.🔀 What does this PIN rule show?
    let pin = "6230";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  36. 36.🔀 What does this PIN rule show?
    let pin = "79844";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 What does this PIN rule show?
    let pin = "5719";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 What does this battery rule show?
    let battery = 78;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  40. 40.🔀 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) Bronze (b) Silver (c) Gold

Answer key

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

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