← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 45 · 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 PIN rule show?
    let pin = "1538";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  2. 2.🔀 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!
  3. 3.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) = (d) !==
  4. 4.🔀 What does this PIN rule show?
    let pin = "23806";
    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 = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  6. 6.🔀 What does this battery rule show?
    let battery = 11;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  7. 7.🔀 What does >= mean? (a) not equal (b) less than (c) smaller or equal (d) greater than or equal
  8. 8.🔀 When does the else part run? (a) always (b) never (c) when the test is false (d) when the test is true
  9. 9.🔀 Which badge does this quiz app show?
    let marks = 80;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  10. 10.🔀 What number does this shop app show?
    let total = 480;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  11. 11.🔀 What does this PIN rule show?
    let pin = "83879";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  12. 12.🔀 What does if / else let an app do? (a) repeat forever (b) save a photo (c) draw a screen (d) pick one of two actions
  13. 13.🔀 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) Silver (b) Bronze (c) Gold
  14. 14.🔀 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
  15. 15.🔀 What does this PIN rule show?
    let pin = "69763";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  16. 16.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) all of them (d) only one
  17. 17.🔀 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!
  18. 18.🔀 What does this PIN rule show?
    let pin = "1284";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  19. 19.🔀 What does this PIN rule show?
    let pin = "96338";
    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 = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  21. 21.🔀 What number does this shop app show?
    let total = 550;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What does this PIN rule show?
    let pin = "44610";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  23. 23.🔀 What does this battery rule show?
    let battery = 12;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  24. 24.🔀 What does this PIN rule show?
    let pin = "3221";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  25. 25.🔀 What does this battery rule show?
    let battery = 70;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 What number does this shop app show?
    let total = 850;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  27. 27.🔀 Which badge does this quiz app show?
    let marks = 57;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  28. 28.🔀 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
  29. 29.🔀 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!
  30. 30.🔀 What number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 What number does this shop app show?
    let total = 510;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does this battery rule show?
    let battery = 3;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 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) Bronze (c) Silver
  34. 34.🔀 What does this battery rule show?
    let battery = 99;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  35. 35.🔀 What number does this shop app show?
    let total = 450;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this battery rule show?
    let battery = 92;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 63;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  38. 38.🔀 What number does this shop app show?
    let total = 620;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 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) Silver (b) Gold (c) Bronze
  40. 40.🔀 What number does this shop app show?
    let total = 640;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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