← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 17 · 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 = 98;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  2. 2.🔀 What does this battery rule show?
    let battery = 31;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  3. 3.🔀 What does this PIN rule show?
    let pin = "53587";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 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
  5. 5.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) = (c) => (d) !==
  6. 6.🔀 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!
  7. 7.🔀 What number does this shop app show?
    let total = 310;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 What does this sign-up rule show?
    let age = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  9. 9.🔀 What does this PIN rule show?
    let pin = "46467";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  10. 10.🔀 What does this PIN rule show?
    let pin = "840";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  11. 11.🔀 What does >= mean? (a) less than (b) smaller or equal (c) not equal (d) greater than or equal
  12. 12.🔀 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!
  13. 13.🔀 What does this battery rule show?
    let battery = 45;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  14. 14.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) two (d) all of them
  15. 15.🔀 What does this battery rule show?
    let battery = 7;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  16. 16.🔀 What does this PIN rule show?
    let pin = "9677";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  17. 17.🔀 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
  18. 18.🔀 Which badge does this quiz app show?
    let marks = 87;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  19. 19.🔀 What does this battery rule show?
    let battery = 28;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  20. 20.🔀 What number does this shop app show?
    let total = 410;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 62;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  22. 22.🔀 What does this battery rule show?
    let battery = 90;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  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) when the test is false (b) never (c) when the test is true (d) always
  25. 25.🔀 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!
  26. 26.🔀 What does this PIN rule show?
    let pin = "15343";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  27. 27.🔀 Which badge does this quiz app show?
    let marks = 61;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  28. 28.🔀 What does this PIN rule show?
    let pin = "6250";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  29. 29.🔀 What number does this shop app show?
    let total = 460;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  30. 30.🔀 What does this battery rule show?
    let battery = 75;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 What does this PIN rule show?
    let pin = "6615";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  32. 32.🔀 What does this sign-up rule show?
    let age = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  33. 33.🔀 What does this battery rule show?
    let battery = 65;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  34. 34.🔀 What does this PIN rule show?
    let pin = "23243";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  35. 35.🔀 What does this PIN rule show?
    let pin = "64030";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  36. 36.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 What does this PIN rule show?
    let pin = "88066";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  38. 38.🔀 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
  39. 39.🔀 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) Gold (b) Silver (c) Bronze
  40. 40.🔀 What does this PIN rule show?
    let pin = "217";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

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

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