← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 52 · 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 = 22;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  2. 2.🔀 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
  3. 3.🔀 What number does this shop app show?
    let total = 860;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 What does this battery rule show?
    let battery = 63;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  5. 5.🔀 What does this battery rule show?
    let battery = 93;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  6. 6.🔀 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
  7. 7.🔀 Which badge does this quiz app show?
    let marks = 56;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  8. 8.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) only one (d) all of them
  9. 9.🔀 What does this PIN rule show?
    let pin = "991";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  10. 10.🔀 When does the else part run? (a) when the test is true (b) always (c) never (d) when the test is false
  11. 11.🔀 What does this PIN rule show?
    let pin = "702";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  12. 12.🔀 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!
  13. 13.🔀 What does this PIN rule show?
    let pin = "9620";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  14. 14.🔀 What does this PIN rule show?
    let pin = "34575";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 What does this PIN rule show?
    let pin = "3802";
    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 = 82;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  17. 17.🔀 What number does this shop app show?
    let total = 330;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) === (c) = (d) !==
  19. 19.🔀 What does this PIN rule show?
    let pin = "646";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 What does this battery rule show?
    let battery = 56;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 41;
    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 = 29;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  23. 23.🔀 What does this PIN rule show?
    let pin = "135";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  24. 24.🔀 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
  25. 25.🔀 What does this PIN rule show?
    let pin = "9232";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  26. 26.🔀 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
  27. 27.🔀 What number does this shop app show?
    let total = 700;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What does this PIN rule show?
    let pin = "94525";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  29. 29.🔀 Which badge does this quiz app show?
    let marks = 92;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  30. 30.🔀 What number does this shop app show?
    let total = 670;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 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
  32. 32.🔀 What does this PIN rule show?
    let pin = "7279";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  33. 33.🔀 What does this battery rule show?
    let battery = 49;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  34. 34.🔀 What does this battery rule show?
    let battery = 13;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  35. 35.🔀 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) Gold (b) Bronze (c) Silver
  36. 36.🔀 What does this PIN rule show?
    let pin = "2863";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 What number does this shop app show?
    let total = 780;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 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!
  39. 39.🔀 What does this battery rule show?
    let battery = 5;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  40. 40.🔀 What does this PIN rule show?
    let pin = "66435";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

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

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