← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 27 · 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 = 92;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  2. 2.🔀 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
  3. 3.🔀 What does this battery rule show?
    let battery = 45;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  4. 4.🔀 What does this PIN rule show?
    let pin = "5907";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  5. 5.🔀 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
  6. 6.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
  7. 7.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  8. 8.🔀 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) Bronze (b) Silver (c) Gold
  9. 9.🔀 What does this PIN rule show?
    let pin = "4676";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  10. 10.🔀 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
  11. 11.🔀 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!
  12. 12.🔀 What does this PIN rule show?
    let pin = "3763";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  13. 13.🔀 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
  14. 14.🔀 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) Bronze (b) Gold (c) Silver
  15. 15.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) => (c) === (d) =
  16. 16.🔀 What does this battery rule show?
    let battery = 90;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  17. 17.🔀 What does this battery rule show?
    let battery = 25;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  18. 18.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  19. 19.🔀 Which badge does this quiz app show?
    let marks = 59;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  20. 20.🔀 What does this battery rule show?
    let battery = 7;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  21. 21.🔀 What number does this shop app show?
    let total = 690;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What does this PIN rule show?
    let pin = "7166";
    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 = 70;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  24. 24.🔀 What does this PIN rule show?
    let pin = "690";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  25. 25.🔀 What number does this shop app show?
    let total = 670;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  26. 26.🔀 What does if / else let an app do? (a) repeat forever (b) save a photo (c) pick one of two actions (d) draw a screen
  27. 27.🔀 What does this PIN rule show?
    let pin = "5014";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  28. 28.🔀 What does this PIN rule show?
    let pin = "742";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  29. 29.🔀 What does this sign-up rule show?
    let age = 16;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  30. 30.🔀 What number does this shop app show?
    let total = 500;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 What does this battery rule show?
    let battery = 66;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  32. 32.🔀 What does this battery rule show?
    let battery = 23;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 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!
  34. 34.🔀 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
  35. 35.🔀 What number does this shop app show?
    let total = 860;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 What does this battery rule show?
    let battery = 83;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  38. 38.🔀 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) Bronze (b) Silver (c) Gold
  39. 39.🔀 What does this PIN rule show?
    let pin = "37273";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  40. 40.🔀 Which badge does this quiz app show?
    let marks = 67;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze

Answer key

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

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