← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 42 · 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 = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 Which badge does this quiz app show?
    let marks = 93;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  3. 3.🔀 What does this battery rule show?
    let battery = 30;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  4. 4.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
  5. 5.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) pick one of two actions (d) repeat forever
  6. 6.🔀 What number does this shop app show?
    let total = 310;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  7. 7.🔀 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
  8. 8.🔀 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) Gold (b) Bronze (c) Silver
  9. 9.🔀 What does this battery rule show?
    let battery = 28;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  10. 10.🔀 Which badge does this quiz app show?
    let marks = 39;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  11. 11.🔀 What does this battery rule show?
    let battery = 24;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  12. 12.🔀 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!
  13. 13.🔀 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!
  14. 14.🔀 What number does this shop app show?
    let total = 770;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  15. 15.🔀 What does this PIN rule show?
    let pin = "75746";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  16. 16.🔀 Which badge does this quiz app show?
    let marks = 68;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  17. 17.🔀 What does this PIN rule show?
    let pin = "59223";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  18. 18.🔀 What does this battery rule show?
    let battery = 36;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  19. 19.🔀 What does this sign-up rule show?
    let age = 11;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  20. 20.🔀 What does this PIN rule show?
    let pin = "51728";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  21. 21.🔀 What does this PIN rule show?
    let pin = "2664";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  22. 22.🔀 What does this PIN rule show?
    let pin = "159";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  23. 23.🔀 Which badge does this quiz app show?
    let marks = 55;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  24. 24.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) all of them (d) none
  25. 25.🔀 Which badge does this quiz app show?
    let marks = 23;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  26. 26.🔀 What does this PIN rule show?
    let pin = "56824";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  27. 27.🔀 What number does this shop app show?
    let total = 670;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What does this PIN rule show?
    let pin = "73865";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  29. 29.🔀 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) Silver (b) Bronze (c) Gold
  30. 30.🔀 Which badge does this quiz app show?
    let marks = 31;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  31. 31.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 37;
    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 sign-up rule show?
    let age = 10;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  34. 34.🔀 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
  35. 35.🔀 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
  36. 36.🔀 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) Silver (b) Gold (c) Bronze
  37. 37.🔀 What does this battery rule show?
    let battery = 43;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  38. 38.🔀 What does this battery rule show?
    let battery = 87;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  39. 39.🔀 Which badge does this quiz app show?
    let marks = 50;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  40. 40.🔀 What does this battery rule show?
    let battery = 82;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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