← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 86 · 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 number does this shop app show?
    let total = 510;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 What number does this shop app show?
    let total = 560;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  3. 3.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) only one (d) all of them
  4. 4.🔀 What does this PIN rule show?
    let pin = "102";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  5. 5.🔀 What does this PIN rule show?
    let pin = "4897";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  6. 6.🔀 Which badge does this quiz app show?
    let marks = 98;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  7. 7.🔀 What does this battery rule show?
    let battery = 16;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  8. 8.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
  9. 9.🔀 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!
  10. 10.🔀 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) Bronze (b) Gold (c) Silver
  11. 11.🔀 What does this PIN rule show?
    let pin = "9661";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  12. 12.🔀 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
  13. 13.🔀 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
  14. 14.🔀 What does this PIN rule show?
    let pin = "254";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 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
  16. 16.🔀 What does this PIN rule show?
    let pin = "87592";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  17. 17.🔀 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
  18. 18.🔀 What number does this shop app show?
    let total = 710;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  19. 19.🔀 What does this sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  20. 20.🔀 Which badge does this quiz app show?
    let marks = 29;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  21. 21.🔀 What number does this shop app show?
    let total = 390;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 What number does this shop app show?
    let total = 530;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  23. 23.🔀 What does this battery rule show?
    let battery = 67;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  24. 24.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) === (d) !==
  25. 25.🔀 What does this PIN rule show?
    let pin = "246";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 What does this PIN rule show?
    let pin = "451";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  27. 27.🔀 What number does this shop app show?
    let total = 840;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What number does this shop app show?
    let total = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 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!
  30. 30.🔀 What does this PIN rule show?
    let pin = "50324";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  31. 31.🔀 What number does this shop app show?
    let total = 720;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) save a photo (d) pick one of two actions
  33. 33.🔀 What does this PIN rule show?
    let pin = "1687";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  34. 34.🔀 Which badge does this quiz app show?
    let marks = 40;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  35. 35.🔀 What number does this shop app show?
    let total = 880;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 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
  37. 37.🔀 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
  38. 38.🔀 What does this battery rule show?
    let battery = 28;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  39. 39.🔀 What number does this shop app show?
    let total = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 What number does this shop app show?
    let total = 350;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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