← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 5 · 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) not equal (b) smaller or equal (c) less than (d) greater than or equal
  2. 2.🔀 When does the else part run? (a) never (b) always (c) when the test is true (d) when the test is false
  3. 3.🔀 What does this battery rule show?
    let battery = 11;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  4. 4.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
  5. 5.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) all of them (d) none
  6. 6.🔀 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
  7. 7.🔀 What number does this shop app show?
    let total = 570;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 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
  9. 9.🔀 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) Bronze (b) Gold (c) Silver
  10. 10.🔀 What does this PIN rule show?
    let pin = "1226";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  11. 11.🔀 What does this battery rule show?
    let battery = 22;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  12. 12.🔀 What does if / else let an app do? (a) repeat forever (b) save a photo (c) pick one of two actions (d) draw a screen
  13. 13.🔀 What does this battery rule show?
    let battery = 4;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  14. 14.🔀 What does this battery rule show?
    let battery = 19;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  15. 15.🔀 What does this battery rule show?
    let battery = 93;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  16. 16.🔀 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
  17. 17.🔀 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!
  18. 18.🔀 What does this sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  19. 19.🔀 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) Bronze (b) Silver (c) Gold
  20. 20.🔀 Which badge does this quiz app show?
    let marks = 38;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  21. 21.🔀 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!
  22. 22.🔀 What does this battery rule show?
    let battery = 83;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  23. 23.🔀 What does this PIN rule show?
    let pin = "719";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  24. 24.🔀 What does this PIN rule show?
    let pin = "709";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  25. 25.🔀 What does this PIN rule show?
    let pin = "7183";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 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
  27. 27.🔀 What does this PIN rule show?
    let pin = "87454";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  28. 28.🔀 What number does this shop app show?
    let total = 260;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 Which badge does this quiz app show?
    let marks = 67;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  30. 30.🔀 What does this battery rule show?
    let battery = 49;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  31. 31.🔀 What does this PIN rule show?
    let pin = "87656";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  32. 32.🔀 What does this battery rule show?
    let battery = 80;
    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 = 62;
    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 = "918";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  35. 35.🔀 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) Gold (b) Silver (c) Bronze
  36. 36.🔀 What number does this shop app show?
    let total = 640;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 86;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  38. 38.🔀 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) Bronze (c) Gold
  39. 39.🔀 What number does this shop app show?
    let total = 780;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 What number does this shop app show?
    let total = 400;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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