← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

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

Answer key

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

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