← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 67 · 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.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) all of them (d) only one
  2. 2.🔀 What number does this shop app show?
    let total = 320;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  3. 3.🔀 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
  4. 4.🔀 What number does this shop app show?
    let total = 360;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  5. 5.🔀 Which badge does this quiz app show?
    let marks = 42;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  6. 6.🔀 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
  7. 7.🔀 What does this battery rule show?
    let battery = 48;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  8. 8.🔀 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
  9. 9.🔀 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) Silver (b) Gold (c) Bronze
  10. 10.🔀 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
  11. 11.🔀 What does if / else let an app do? (a) repeat forever (b) draw a screen (c) save a photo (d) pick one of two actions
  12. 12.🔀 Which badge does this quiz app show?
    let marks = 27;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  13. 13.🔀 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!
  14. 14.🔀 Which badge does this quiz app show?
    let marks = 86;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  15. 15.🔀 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!
  16. 16.🔀 What does this battery rule show?
    let battery = 70;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  17. 17.🔀 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
  18. 18.🔀 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!
  19. 19.🔀 What does this battery rule show?
    let battery = 7;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  20. 20.🔀 What does this PIN rule show?
    let pin = "8478";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  21. 21.🔀 What does this PIN rule show?
    let pin = "774";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  22. 22.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) less than (d) not equal
  23. 23.🔀 What does this PIN rule show?
    let pin = "3818";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  24. 24.🔀 When does the else part run? (a) always (b) when the test is false (c) never (d) when the test is true
  25. 25.🔀 What does this battery rule show?
    let battery = 89;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) => (d) !==
  27. 27.🔀 What number does this shop app show?
    let total = 270;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What number does this shop app show?
    let total = 230;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 What does this battery rule show?
    let battery = 8;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  30. 30.🔀 Which badge does this quiz app show?
    let marks = 41;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  31. 31.🔀 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
  32. 32.🔀 What number does this shop app show?
    let total = 700;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 Which badge does this quiz app show?
    let marks = 47;
    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 = 61;
    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 = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this PIN rule show?
    let pin = "35890";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  37. 37.🔀 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) Gold (b) Bronze (c) Silver
  38. 38.🔀 What number does this shop app show?
    let total = 340;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 What does this PIN rule show?
    let pin = "22855";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  40. 40.🔀 What does this battery rule show?
    let battery = 69;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery

Answer key

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

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