← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 8 · 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 = 250;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 What does this battery rule show?
    let battery = 53;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  3. 3.🔀 What number does this shop app show?
    let total = 890;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 Which badge does this quiz app show?
    let marks = 33;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  5. 5.🔀 Which badge does this quiz app show?
    let marks = 25;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  6. 6.🔀 Which badge does this quiz app show?
    let marks = 30;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  7. 7.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 What number does this shop app show?
    let total = 450;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  9. 9.🔀 What number does this shop app show?
    let total = 400;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  10. 10.🔀 What does this battery rule show?
    let battery = 37;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  11. 11.🔀 What does this battery rule show?
    let battery = 44;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  12. 12.🔀 What number does this shop app show?
    let total = 790;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) never (d) always
  14. 14.🔀 What does this PIN rule show?
    let pin = "9836";
    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 = "813";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  16. 16.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) only one (d) none
  17. 17.🔀 What does this PIN rule show?
    let pin = "457";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  18. 18.🔀 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
  19. 19.🔀 What does this battery rule show?
    let battery = 33;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  20. 20.🔀 What number does this shop app show?
    let total = 420;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 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
  22. 22.🔀 What does this PIN rule show?
    let pin = "65614";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  23. 23.🔀 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) Gold (b) Bronze (c) Silver
  24. 24.🔀 What does if / else let an app do? (a) repeat forever (b) draw a screen (c) save a photo (d) pick one of two actions
  25. 25.🔀 What does this battery rule show?
    let battery = 46;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 What does this PIN rule show?
    let pin = "125";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  27. 27.🔀 Which badge does this quiz app show?
    let marks = 53;
    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 sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  29. 29.🔀 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
  30. 30.🔀 What does this battery rule show?
    let battery = 96;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  31. 31.🔀 What does this battery rule show?
    let battery = 80;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  32. 32.🔀 What number does this shop app show?
    let total = 500;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 What does this battery rule show?
    let battery = 61;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 98;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  35. 35.🔀 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
  36. 36.🔀 What number does this shop app show?
    let total = 230;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 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
  38. 38.🔀 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
  39. 39.🔀 What does >= mean? (a) less than (b) not equal (c) smaller or equal (d) greater than or equal
  40. 40.🔀 What does this PIN rule show?
    let pin = "2864";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

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

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