← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 7 · 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 number does this shop app show?
    let total = 890;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 Which badge does this quiz app show?
    let marks = 90;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  3. 3.🔀 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
  4. 4.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
  5. 5.🔀 Which badge does this quiz app show?
    let marks = 87;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  6. 6.🔀 What number does this shop app show?
    let total = 790;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  7. 7.🔀 Which badge does this quiz app show?
    let marks = 75;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  8. 8.🔀 Which badge does this quiz app show?
    let marks = 77;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  9. 9.🔀 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
  10. 10.🔀 What does this PIN rule show?
    let pin = "4731";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  11. 11.🔀 What does this PIN rule show?
    let pin = "91653";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  12. 12.🔀 What number does this shop app show?
    let total = 670;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) => (d) ===
  14. 14.🔀 What number does this shop app show?
    let total = 530;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  15. 15.🔀 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) Silver (b) Gold (c) Bronze
  16. 16.🔀 What does this PIN rule show?
    let pin = "427";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  17. 17.🔀 What does this PIN rule show?
    let pin = "27315";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  18. 18.🔀 When does the else part run? (a) always (b) when the test is false (c) never (d) when the test is true
  19. 19.🔀 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) Silver (b) Gold (c) Bronze
  20. 20.🔀 What does this battery rule show?
    let battery = 21;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  21. 21.🔀 What does this battery rule show?
    let battery = 55;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  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 battery rule show?
    let battery = 91;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  24. 24.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  25. 25.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
  26. 26.🔀 What number does this shop app show?
    let total = 340;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 Which badge does this quiz app show?
    let marks = 76;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  28. 28.🔀 What does this PIN rule show?
    let pin = "70491";
    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 = "875";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  30. 30.🔀 What does this battery rule show?
    let battery = 99;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 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
  32. 32.🔀 What does this battery rule show?
    let battery = 62;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 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) Silver (b) Gold (c) Bronze
  34. 34.🔀 What number does this shop app show?
    let total = 660;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 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
  36. 36.🔀 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
  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) Silver (c) Gold
  38. 38.🔀 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!
  39. 39.🔀 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
  40. 40.🔀 What does this battery rule show?
    let battery = 17;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery

Answer key

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

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