← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 10 · 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 sign-up rule show?
    let age = 15;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  2. 2.🔀 What does this sign-up rule show?
    let age = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  3. 3.🔀 What does this PIN rule show?
    let pin = "7041";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 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!
  5. 5.🔀 What does this battery rule show?
    let battery = 74;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  6. 6.🔀 What does >= mean? (a) smaller or equal (b) less than (c) not equal (d) greater than or equal
  7. 7.🔀 What does this battery rule show?
    let battery = 75;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  8. 8.🔀 Which badge does this quiz app show?
    let marks = 54;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  9. 9.🔀 What number does this shop app show?
    let total = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  10. 10.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
  11. 11.🔀 What does this PIN rule show?
    let pin = "404";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  12. 12.🔀 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) Silver (b) Gold (c) Bronze
  13. 13.🔀 What does this battery rule show?
    let battery = 53;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  14. 14.🔀 What does this PIN rule show?
    let pin = "552";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  16. 16.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) === (d) =>
  17. 17.🔀 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
  18. 18.🔀 What does this battery rule show?
    let battery = 49;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  19. 19.🔀 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
  20. 20.🔀 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!
  21. 21.🔀 Which badge does this quiz app show?
    let marks = 76;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  22. 22.🔀 What does this PIN rule show?
    let pin = "532";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  23. 23.🔀 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!
  24. 24.🔀 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) Bronze (b) Gold (c) Silver
  25. 25.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  26. 26.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 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
  28. 28.🔀 What does this PIN rule show?
    let pin = "8540";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  29. 29.🔀 What does this PIN rule show?
    let pin = "60178";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  30. 30.🔀 What does this battery rule show?
    let battery = 1;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  31. 31.🔀 Which badge does this quiz app show?
    let marks = 81;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  32. 32.🔀 What number does this shop app show?
    let total = 810;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 What number does this shop app show?
    let total = 260;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  34. 34.🔀 When does the else part run? (a) when the test is false (b) always (c) when the test is true (d) never
  35. 35.🔀 What does this battery rule show?
    let battery = 55;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  36. 36.🔀 Which badge does this quiz app show?
    let marks = 74;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  37. 37.🔀 What number does this shop app show?
    let total = 900;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 What does this battery rule show?
    let battery = 66;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  39. 39.🔀 What does this battery rule show?
    let battery = 44;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  40. 40.🔀 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) Bronze (b) Gold (c) Silver

Answer key

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

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