← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 16 · 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 = "398";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  2. 2.🔀 What does this PIN rule show?
    let pin = "197";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  3. 3.🔀 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) Gold (b) Bronze (c) Silver
  4. 4.🔀 What does this PIN rule show?
    let pin = "159";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  5. 5.🔀 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
  6. 6.🔀 What does this battery rule show?
    let battery = 11;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  7. 7.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) => (c) !== (d) ===
  8. 8.🔀 What does this PIN rule show?
    let pin = "464";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  9. 9.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  10. 10.🔀 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!
  11. 11.🔀 What does this PIN rule show?
    let pin = "919";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  12. 12.🔀 What number does this shop app show?
    let total = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 What does this PIN rule show?
    let pin = "9984";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  14. 14.🔀 What does this battery rule show?
    let battery = 4;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  15. 15.🔀 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) Gold (b) Silver (c) Bronze
  16. 16.🔀 What number does this shop app show?
    let total = 610;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  17. 17.🔀 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!
  18. 18.🔀 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!
  19. 19.🔀 Which badge does this quiz app show?
    let marks = 80;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  20. 20.🔀 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
  21. 21.🔀 What does this battery rule show?
    let battery = 69;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  22. 22.🔀 What does this PIN rule show?
    let pin = "3104";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  23. 23.🔀 What does this PIN rule show?
    let pin = "584";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  24. 24.🔀 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
  25. 25.🔀 What does >= mean? (a) greater than or equal (b) not equal (c) smaller or equal (d) less than
  26. 26.🔀 What does this PIN rule show?
    let pin = "825";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  27. 27.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
  28. 28.🔀 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
  29. 29.🔀 What does this PIN rule show?
    let pin = "478";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  30. 30.🔀 When does the else part run? (a) when the test is true (b) never (c) when the test is false (d) always
  31. 31.🔀 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
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 86;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  33. 33.🔀 What does this PIN rule show?
    let pin = "1179";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  34. 34.🔀 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!
  35. 35.🔀 What does this battery rule show?
    let battery = 40;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  36. 36.🔀 What number does this shop app show?
    let total = 790;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 What does this PIN rule show?
    let pin = "53582";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 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!
  39. 39.🔀 What does this PIN rule show?
    let pin = "48060";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  40. 40.🔀 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

Answer key

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

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