← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 40 · 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 = 620;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 Which badge does this quiz app show?
    let marks = 30;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  3. 3.🔀 When does the else part run? (a) when the test is true (b) never (c) always (d) when the test is false
  4. 4.🔀 What number does this shop app show?
    let total = 220;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  5. 5.🔀 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) Bronze (b) Gold (c) Silver
  6. 6.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) smaller or equal (d) less than
  7. 7.🔀 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!
  8. 8.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
  9. 9.🔀 What does if / else let an app do? (a) save a photo (b) draw a screen (c) repeat forever (d) pick one of two actions
  10. 10.🔀 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!
  11. 11.🔀 What number does this shop app show?
    let total = 530;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  12. 12.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 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) Gold (b) Silver (c) Bronze
  14. 14.🔀 What does this PIN rule show?
    let pin = "7565";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  15. 15.🔀 What number does this shop app show?
    let total = 340;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  16. 16.🔀 What does this PIN rule show?
    let pin = "2688";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  17. 17.🔀 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
  18. 18.🔀 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) Silver (b) Gold (c) Bronze
  19. 19.🔀 Which badge does this quiz app show?
    let marks = 52;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  20. 20.🔀 What number does this shop app show?
    let total = 700;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  21. 21.🔀 What does this PIN rule show?
    let pin = "9932";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  22. 22.🔀 What does this PIN rule show?
    let pin = "4295";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  23. 23.🔀 Which badge does this quiz app show?
    let marks = 48;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  24. 24.🔀 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!
  25. 25.🔀 Which badge does this quiz app show?
    let marks = 90;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Gold (c) Silver
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 66;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  27. 27.🔀 With if / else if / else, how many parts run? (a) only one (b) all of them (c) none (d) two
  28. 28.🔀 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
  29. 29.🔀 What does this PIN rule show?
    let pin = "10040";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  30. 30.🔀 What does this PIN rule show?
    let pin = "75090";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  31. 31.🔀 What does this PIN rule show?
    let pin = "18149";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  32. 32.🔀 What does this battery rule show?
    let battery = 78;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  33. 33.🔀 What does this PIN rule show?
    let pin = "1503";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  34. 34.🔀 What does this PIN rule show?
    let pin = "88946";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  35. 35.🔀 What does this PIN rule show?
    let pin = "107";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  36. 36.🔀 What does this PIN rule show?
    let pin = "92238";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  37. 37.🔀 What does this PIN rule show?
    let pin = "14594";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 What does this PIN rule show?
    let pin = "846";
    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 = 48;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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