← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 70 · 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.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) two (d) all of them
  2. 2.🔀 What does this PIN rule show?
    let pin = "48445";
    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 = 25;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  4. 4.🔀 What does this battery rule show?
    let battery = 2;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  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 = 8;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  7. 7.🔀 What does if / else let an app do? (a) pick one of two actions (b) repeat forever (c) save a photo (d) draw a screen
  8. 8.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  9. 9.🔀 What does >= mean? (a) greater than or equal (b) smaller or equal (c) less than (d) not equal
  10. 10.🔀 Which badge does this quiz app show?
    let marks = 65;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  11. 11.🔀 What does this PIN rule show?
    let pin = "45552";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  12. 12.🔀 Which badge does this quiz app show?
    let marks = 60;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  13. 13.🔀 When does the else part run? (a) when the test is true (b) never (c) always (d) when the test is false
  14. 14.🔀 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!
  15. 15.🔀 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!
  16. 16.🔀 Which badge does this quiz app show?
    let marks = 91;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  17. 17.🔀 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
  18. 18.🔀 What does this PIN rule show?
    let pin = "588";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  19. 19.🔀 What number does this shop app show?
    let total = 220;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 What number does this shop app show?
    let total = 760;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 69;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  22. 22.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) !== (c) = (d) ===
  23. 23.🔀 What does this PIN rule show?
    let pin = "654";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  24. 24.🔀 What number does this shop app show?
    let total = 830;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  25. 25.🔀 What does this PIN rule show?
    let pin = "30513";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 What number does this shop app show?
    let total = 510;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 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!
  28. 28.🔀 What does this battery rule show?
    let battery = 85;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  29. 29.🔀 What does this PIN rule show?
    let pin = "331";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  30. 30.🔀 What does this PIN rule show?
    let pin = "1447";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  31. 31.🔀 What number does this shop app show?
    let total = 750;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 70;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  33. 33.🔀 What does this battery rule show?
    let battery = 59;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 100;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  35. 35.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  36. 36.🔀 What does this battery rule show?
    let battery = 18;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 36;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  38. 38.🔀 Which badge does this quiz app show?
    let marks = 40;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  39. 39.🔀 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
  40. 40.🔀 What does this battery rule show?
    let battery = 53;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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