← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

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

Answer key

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

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