← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 37 · 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 = 22;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  2. 2.🔀 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
  3. 3.🔀 What number does this shop app show?
    let total = 580;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) = (d) !==
  5. 5.🔀 What does this sign-up rule show?
    let age = 12;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  6. 6.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) less than (d) smaller or equal
  7. 7.🔀 What does this battery rule show?
    let battery = 29;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  8. 8.🔀 What does this battery rule show?
    let battery = 86;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  9. 9.🔀 Which badge does this quiz app show?
    let marks = 43;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  10. 10.🔀 Which badge does this quiz app show?
    let marks = 48;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  11. 11.🔀 With if / else if / else, how many parts run? (a) none (b) only one (c) all of them (d) two
  12. 12.🔀 What does this PIN rule show?
    let pin = "5565";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  13. 13.🔀 What does this PIN rule show?
    let pin = "5582";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  14. 14.🔀 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
  15. 15.🔀 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
  16. 16.🔀 When does the else part run? (a) never (b) when the test is true (c) when the test is false (d) always
  17. 17.🔀 What does this PIN rule show?
    let pin = "2574";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  18. 18.🔀 What does this PIN rule show?
    let pin = "2190";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  19. 19.🔀 What number does this shop app show?
    let total = 760;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 What does this PIN rule show?
    let pin = "513";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  21. 21.🔀 What does this PIN rule show?
    let pin = "674";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  22. 22.🔀 What does this battery rule show?
    let battery = 94;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  23. 23.🔀 What does this battery rule show?
    let battery = 92;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  24. 24.🔀 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
  25. 25.🔀 Which badge does this quiz app show?
    let marks = 45;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  26. 26.🔀 What number does this shop app show?
    let total = 650;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 What does this battery rule show?
    let battery = 95;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  28. 28.🔀 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
  29. 29.🔀 What does this PIN rule show?
    let pin = "7180";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  30. 30.🔀 What number does this shop app show?
    let total = 720;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 What does this PIN rule show?
    let pin = "777";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  32. 32.🔀 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) Silver (b) Bronze (c) Gold
  33. 33.🔀 What does this battery rule show?
    let battery = 5;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  34. 34.🔀 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
  35. 35.🔀 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
  36. 36.🔀 What does this PIN rule show?
    let pin = "70848";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 What number does this shop app show?
    let total = 700;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 Which badge does this quiz app show?
    let marks = 21;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  39. 39.🔀 What number does this shop app show?
    let total = 710;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 What does this battery rule show?
    let battery = 88;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery

Answer key

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

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