← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 56 · 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 = "35861";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  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 does this PIN rule show?
    let pin = "580";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 What does this battery rule show?
    let battery = 52;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  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.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) => (c) = (d) ===
  7. 7.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) two (d) only one
  8. 8.🔀 What does this battery rule show?
    let battery = 48;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  9. 9.🔀 When does the else part run? (a) always (b) when the test is true (c) when the test is false (d) never
  10. 10.🔀 Which badge does this quiz app show?
    let marks = 35;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  11. 11.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  12. 12.🔀 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!
  13. 13.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 What number does this shop app show?
    let total = 390;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  15. 15.🔀 Which badge does this quiz app show?
    let marks = 28;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  16. 16.🔀 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
  17. 17.🔀 What does this PIN rule show?
    let pin = "86140";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  18. 18.🔀 What does this battery rule show?
    let battery = 24;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  19. 19.🔀 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
  20. 20.🔀 What number does this shop app show?
    let total = 330;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 What does this battery rule show?
    let battery = 63;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  22. 22.🔀 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
  23. 23.🔀 Which badge does this quiz app show?
    let marks = 24;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  24. 24.🔀 What does this battery rule show?
    let battery = 97;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  25. 25.🔀 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) Gold (c) Silver
  26. 26.🔀 What does this PIN rule show?
    let pin = "508";
    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 = 85;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  28. 28.🔀 What does this battery rule show?
    let battery = 45;
    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 = "300";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  30. 30.🔀 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
  31. 31.🔀 What number does this shop app show?
    let total = 230;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does this battery rule show?
    let battery = 20;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 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
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 78;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  35. 35.🔀 What does this battery rule show?
    let battery = 56;
    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 = 650;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 32;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  38. 38.🔀 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!
  39. 39.🔀 Which badge does this quiz app show?
    let marks = 84;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  40. 40.🔀 What does this PIN rule show?
    let pin = "522";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

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

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