← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 21 · 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 >= mean? (a) greater than or equal (b) less than (c) not equal (d) smaller or equal
  2. 2.🔀 Which badge does this quiz app show?
    let marks = 94;
    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 PIN rule show?
    let pin = "28185";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  4. 4.🔀 What does this PIN rule show?
    let pin = "600";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  5. 5.🔀 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) Bronze (c) Gold
  6. 6.🔀 What does this PIN rule show?
    let pin = "434";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  7. 7.🔀 What does this PIN rule show?
    let pin = "35016";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  8. 8.🔀 What does if / else let an app do? (a) save a photo (b) draw a screen (c) repeat forever (d) pick one of two actions
  9. 9.🔀 What does this battery rule show?
    let battery = 15;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  10. 10.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) => (d) ===
  11. 11.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) only one (d) none
  12. 12.🔀 What does this PIN rule show?
    let pin = "8644";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 What number does this shop app show?
    let total = 300;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 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
  15. 15.🔀 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
  16. 16.🔀 What does this PIN rule show?
    let pin = "63880";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  17. 17.🔀 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
  18. 18.🔀 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
  19. 19.🔀 What does this battery rule show?
    let battery = 10;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  20. 20.🔀 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
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 20;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  22. 22.🔀 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
  23. 23.🔀 What number does this shop app show?
    let total = 400;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  24. 24.🔀 What number does this shop app show?
    let total = 360;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  25. 25.🔀 What does this battery rule show?
    let battery = 23;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  26. 26.🔀 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!
  27. 27.🔀 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) Gold (b) Silver (c) Bronze
  28. 28.🔀 What does this battery rule show?
    let battery = 42;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  29. 29.🔀 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
  30. 30.🔀 What number does this shop app show?
    let total = 490;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 Which badge does this quiz app show?
    let marks = 83;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  32. 32.🔀 What number does this shop app show?
    let total = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 What does this battery rule show?
    let battery = 50;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  34. 34.🔀 What does this PIN rule show?
    let pin = "224";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  35. 35.🔀 What does this PIN rule show?
    let pin = "95547";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  36. 36.🔀 What does this PIN rule show?
    let pin = "97384";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  37. 37.🔀 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) Gold (b) Silver (c) Bronze
  38. 38.🔀 What number does this shop app show?
    let total = 450;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 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
  40. 40.🔀 What number does this shop app show?
    let total = 710;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

  1. greater than or equal
  2. Gold
  3. Use 4 digits
  4. Use 4 digits
  5. Silver
  6. Use 4 digits
  7. Use 4 digits
  8. pick one of two actions
  9. Low battery
  10. ===
  11. only one
  12. PIN saved
  13. 300
  14. Welcome!
  15. Welcome!
  16. Use 4 digits
  17. Battery OK
  18. Battery OK
  19. Low battery
  20. Ask a parent
  21. Bronze
  22. Battery OK
  23. 400
  24. 360
  25. Battery OK
  26. Welcome!
  27. Bronze
  28. Battery OK
  29. Battery OK
  30. 490
  31. Gold
  32. 690
  33. Battery OK
  34. Use 4 digits
  35. Use 4 digits
  36. Use 4 digits
  37. Silver
  38. 450
  39. Battery OK
  40. 660

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