← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 38 · 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 = 9;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  2. 2.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) all of them (d) only one
  3. 3.🔀 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
  4. 4.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) !== (d) =
  5. 5.🔀 What number does this shop app show?
    let total = 580;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  6. 6.🔀 When does the else part run? (a) when the test is true (b) always (c) never (d) when the test is false
  7. 7.🔀 Which badge does this quiz app show?
    let marks = 97;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  8. 8.🔀 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
  9. 9.🔀 Which badge does this quiz app show?
    let marks = 69;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  10. 10.🔀 What does this PIN rule show?
    let pin = "82259";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  11. 11.🔀 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) Gold (b) Bronze (c) Silver
  12. 12.🔀 What does >= mean? (a) less than (b) not equal (c) smaller or equal (d) greater than or equal
  13. 13.🔀 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) Silver (c) Gold
  14. 14.🔀 What does this battery rule show?
    let battery = 38;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  15. 15.🔀 What number does this shop app show?
    let total = 460;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  16. 16.🔀 What does this PIN rule show?
    let pin = "7011";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  17. 17.🔀 What does this PIN rule show?
    let pin = "71930";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  18. 18.🔀 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
  19. 19.🔀 What does this PIN rule show?
    let pin = "77824";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  20. 20.🔀 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!
  21. 21.🔀 What does this battery rule show?
    let battery = 95;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  22. 22.🔀 Which badge does this quiz app show?
    let marks = 96;
    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 sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  24. 24.🔀 What does this battery rule show?
    let battery = 19;
    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 = 75;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  26. 26.🔀 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) Gold (b) Bronze (c) Silver
  27. 27.🔀 What does this battery rule show?
    let battery = 90;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  28. 28.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 Which badge does this quiz app show?
    let marks = 28;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  30. 30.🔀 What does this battery rule show?
    let battery = 12;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  31. 31.🔀 What number does this shop app show?
    let total = 440;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does this PIN rule show?
    let pin = "984";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  33. 33.🔀 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!
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 94;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  35. 35.🔀 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) Gold (b) Bronze (c) Silver
  36. 36.🔀 What does this PIN rule show?
    let pin = "15388";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 What number does this shop app show?
    let total = 820;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 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
  39. 39.🔀 What number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 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!

Answer key

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

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