← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 39 · 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 battery rule show?
    let battery = 23;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  2. 2.🔀 What number does this shop app show?
    let total = 810;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  3. 3.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
  4. 4.🔀 What number does this shop app show?
    let total = 440;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  5. 5.🔀 What does this battery rule show?
    let battery = 56;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  6. 6.🔀 What does this sign-up rule show?
    let age = 11;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  7. 7.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) two (d) none
  8. 8.🔀 What does this battery rule show?
    let battery = 30;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  9. 9.🔀 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
  10. 10.🔀 What number does this shop app show?
    let total = 480;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  11. 11.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
  12. 12.🔀 Which badge does this quiz app show?
    let marks = 36;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  13. 13.🔀 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
  14. 14.🔀 What does this PIN rule show?
    let pin = "139";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 What does this PIN rule show?
    let pin = "5661";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  16. 16.🔀 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
  17. 17.🔀 Which badge does this quiz app show?
    let marks = 29;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  18. 18.🔀 What does this PIN rule show?
    let pin = "4300";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  19. 19.🔀 What does this PIN rule show?
    let pin = "311";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 What does this battery rule show?
    let battery = 67;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  22. 22.🔀 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
  23. 23.🔀 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
  24. 24.🔀 Which badge does this quiz app show?
    let marks = 34;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  25. 25.🔀 What number does this shop app show?
    let total = 630;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 27;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  27. 27.🔀 What does this PIN rule show?
    let pin = "2993";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 69;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  29. 29.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  30. 30.🔀 What does this battery rule show?
    let battery = 18;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 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
  32. 32.🔀 What number does this shop app show?
    let total = 350;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 What does this battery rule show?
    let battery = 53;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  34. 34.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) === (c) !== (d) =
  35. 35.🔀 What number does this shop app show?
    let total = 750;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this PIN rule show?
    let pin = "618";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 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
  38. 38.🔀 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) Silver (c) Gold
  39. 39.🔀 What does this battery rule show?
    let battery = 9;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  40. 40.🔀 What does this PIN rule show?
    let pin = "9461";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

  1. Battery OK
  2. 760
  3. greater than or equal
  4. 440
  5. Battery OK
  6. Ask a parent
  7. only one
  8. Battery OK
  9. Bronze
  10. 480
  11. when the test is false
  12. Bronze
  13. Welcome!
  14. Use 4 digits
  15. PIN saved
  16. Welcome!
  17. Bronze
  18. PIN saved
  19. Use 4 digits
  20. 320
  21. Battery OK
  22. Low battery
  23. Welcome!
  24. Bronze
  25. 580
  26. Bronze
  27. PIN saved
  28. Silver
  29. 510
  30. Low battery
  31. Silver
  32. 350
  33. Battery OK
  34. ===
  35. 700
  36. Use 4 digits
  37. Ask a parent
  38. Bronze
  39. Low battery
  40. PIN saved

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