← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 2 · 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 = 73;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  2. 2.🔀 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!
  3. 3.🔀 What does this PIN rule show?
    let pin = "24316";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  4. 4.🔀 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) Gold (b) Bronze (c) Silver
  5. 5.🔀 What number does this shop app show?
    let total = 750;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  6. 6.🔀 What does this PIN rule show?
    let pin = "2097";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  7. 7.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 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
  9. 9.🔀 What does >= mean? (a) not equal (b) less than (c) smaller or equal (d) greater than or equal
  10. 10.🔀 What does this PIN rule show?
    let pin = "307";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  11. 11.🔀 Which badge does this quiz app show?
    let marks = 52;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  12. 12.🔀 What does this battery rule show?
    let battery = 79;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  13. 13.🔀 Which badge does this quiz app show?
    let marks = 79;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  14. 14.🔀 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
  15. 15.🔀 What does this PIN rule show?
    let pin = "62928";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  16. 16.🔀 What does this battery rule show?
    let battery = 16;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  17. 17.🔀 What number does this shop app show?
    let total = 370;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What does this battery rule show?
    let battery = 76;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  19. 19.🔀 With if / else if / else, how many parts run? (a) two (b) all of them (c) only one (d) none
  20. 20.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) !== (c) = (d) =>
  21. 21.🔀 What does this sign-up rule show?
    let age = 16;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  22. 22.🔀 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
  23. 23.🔀 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!
  24. 24.🔀 What does this battery rule show?
    let battery = 26;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  25. 25.🔀 What does this PIN rule show?
    let pin = "8040";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 66;
    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 battery rule show?
    let battery = 35;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  28. 28.🔀 What does this battery rule show?
    let battery = 23;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  29. 29.🔀 What does this battery rule show?
    let battery = 47;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  30. 30.🔀 What number does this shop app show?
    let total = 880;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 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
  32. 32.🔀 What does this PIN rule show?
    let pin = "348";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  33. 33.🔀 What does this PIN rule show?
    let pin = "112";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  34. 34.🔀 What does this PIN rule show?
    let pin = "276";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  35. 35.🔀 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
  36. 36.🔀 Which badge does this quiz app show?
    let marks = 43;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  37. 37.🔀 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) Bronze (b) Silver (c) Gold
  38. 38.🔀 What number does this shop app show?
    let total = 660;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 Which badge does this quiz app show?
    let marks = 64;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  40. 40.🔀 What does this battery rule show?
    let battery = 29;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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