← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 34 · 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 = "3067";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  2. 2.🔀 When does the else part run? (a) when the test is false (b) when the test is true (c) always (d) never
  3. 3.🔀 What does this PIN rule show?
    let pin = "2721";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 Which badge does this quiz app show?
    let marks = 97;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  5. 5.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) repeat forever (d) pick one of two actions
  6. 6.🔀 Which badge does this quiz app show?
    let marks = 81;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  7. 7.🔀 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) Silver (b) Bronze (c) Gold
  8. 8.🔀 What does this PIN rule show?
    let pin = "8616";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  9. 9.🔀 What does this PIN rule show?
    let pin = "273";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  10. 10.🔀 What number does this shop app show?
    let total = 290;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  11. 11.🔀 What does this sign-up rule show?
    let age = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  12. 12.🔀 What does this battery rule show?
    let battery = 50;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  13. 13.🔀 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
  14. 14.🔀 What does this battery rule show?
    let battery = 43;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  15. 15.🔀 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
  16. 16.🔀 What number does this shop app show?
    let total = 690;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  17. 17.🔀 What does this battery rule show?
    let battery = 47;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  18. 18.🔀 What does this battery rule show?
    let battery = 30;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  19. 19.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) !== (c) => (d) =
  20. 20.🔀 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
  21. 21.🔀 What does this PIN rule show?
    let pin = "8510";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  22. 22.🔀 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
  23. 23.🔀 What number does this shop app show?
    let total = 870;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  24. 24.🔀 What does this battery rule show?
    let battery = 40;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  25. 25.🔀 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
  26. 26.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) less than (d) not equal
  27. 27.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) none (d) only one
  28. 28.🔀 What does this PIN rule show?
    let pin = "7635";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  29. 29.🔀 What does this PIN rule show?
    let pin = "133";
    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 = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  31. 31.🔀 Which badge does this quiz app show?
    let marks = 68;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  32. 32.🔀 What does this battery rule show?
    let battery = 98;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 What does this sign-up rule show?
    let age = 9;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  34. 34.🔀 What does this PIN rule show?
    let pin = "2999";
    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 = 91;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  36. 36.🔀 What does this PIN rule show?
    let pin = "72904";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 What does this PIN rule show?
    let pin = "758";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 What does this PIN rule show?
    let pin = "121";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  39. 39.🔀 What number does this shop app show?
    let total = 640;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 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) Silver (b) Bronze (c) Gold

Answer key

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

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