← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 69 · 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.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) = (c) !== (d) =>
  2. 2.🔀 What does this battery rule show?
    let battery = 94;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  3. 3.🔀 What does this PIN rule show?
    let pin = "202";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  4. 4.🔀 What does if / else let an app do? (a) repeat forever (b) pick one of two actions (c) save a photo (d) draw a screen
  5. 5.🔀 What does this battery rule show?
    let battery = 83;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  6. 6.🔀 Which badge does this quiz app show?
    let marks = 96;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  7. 7.🔀 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
  8. 8.🔀 What does this PIN rule show?
    let pin = "282";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  9. 9.🔀 What does >= mean? (a) not equal (b) less than (c) greater than or equal (d) smaller or equal
  10. 10.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
  11. 11.🔀 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!
  12. 12.🔀 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) Silver (c) Bronze
  13. 13.🔀 What does this battery rule show?
    let battery = 76;
    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 = "2246";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  15. 15.🔀 What does this PIN rule show?
    let pin = "859";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  16. 16.🔀 What does this battery rule show?
    let battery = 60;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  17. 17.🔀 What does this sign-up rule show?
    let age = 11;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  18. 18.🔀 What number does this shop app show?
    let total = 380;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  19. 19.🔀 With if / else if / else, how many parts run? (a) two (b) all of them (c) none (d) only one
  20. 20.🔀 Which badge does this quiz app show?
    let marks = 61;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  21. 21.🔀 What does this PIN rule show?
    let pin = "60869";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  22. 22.🔀 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) Bronze (b) Gold (c) Silver
  23. 23.🔀 What does this battery rule show?
    let battery = 22;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  24. 24.🔀 What number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  25. 25.🔀 Which badge does this quiz app show?
    let marks = 64;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  26. 26.🔀 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
  27. 27.🔀 What does this sign-up rule show?
    let age = 12;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  28. 28.🔀 What does this PIN rule show?
    let pin = "677";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  29. 29.🔀 What does this battery rule show?
    let battery = 32;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  30. 30.🔀 What number does this shop app show?
    let total = 500;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 What number does this shop app show?
    let total = 650;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 What does this PIN rule show?
    let pin = "4552";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  33. 33.🔀 Which badge does this quiz app show?
    let marks = 21;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  34. 34.🔀 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!
  35. 35.🔀 What number does this shop app show?
    let total = 620;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What number does this shop app show?
    let total = 810;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 What number does this shop app show?
    let total = 740;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  38. 38.🔀 What number does this shop app show?
    let total = 680;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  39. 39.🔀 Which badge does this quiz app show?
    let marks = 87;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  40. 40.🔀 What does this PIN rule show?
    let pin = "5305";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved

Answer key

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

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