← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 66 · 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) smaller or equal (b) less than (c) greater than or equal (d) not equal
  2. 2.🔀 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!
  3. 3.🔀 What does this battery rule show?
    let battery = 70;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  4. 4.🔀 What does this battery rule show?
    let battery = 81;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  5. 5.🔀 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!
  6. 6.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) draw a screen (d) pick one of two actions
  7. 7.🔀 What does this battery rule show?
    let battery = 57;
    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 = 90;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  9. 9.🔀 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!
  10. 10.🔀 What does this sign-up rule show?
    let age = 17;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  11. 11.🔀 Which badge does this quiz app show?
    let marks = 24;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  12. 12.🔀 What does this PIN rule show?
    let pin = "83162";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  13. 13.🔀 What does this PIN rule show?
    let pin = "4618";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  14. 14.🔀 Which badge does this quiz app show?
    let marks = 23;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  15. 15.🔀 What does this battery rule show?
    let battery = 98;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  16. 16.🔀 Which badge does this quiz app show?
    let marks = 73;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  17. 17.🔀 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!
  18. 18.🔀 What does this PIN rule show?
    let pin = "269";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  19. 19.🔀 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!
  20. 20.🔀 What does this PIN rule show?
    let pin = "153";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  21. 21.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Ask a parent (b) Welcome!
  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) Gold (b) Silver (c) Bronze
  23. 23.🔀 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
  24. 24.🔀 What does this PIN rule show?
    let pin = "768";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  25. 25.🔀 What does this PIN rule show?
    let pin = "2979";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 What does this battery rule show?
    let battery = 93;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  27. 27.🔀 When does the else part run? (a) never (b) when the test is true (c) when the test is false (d) always
  28. 28.🔀 What does this battery rule show?
    let battery = 66;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  29. 29.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) !== (c) => (d) =
  30. 30.🔀 What does this PIN rule show?
    let pin = "74649";
    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 = 410;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  32. 32.🔀 Which badge does this quiz app show?
    let marks = 81;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  33. 33.🔀 What does this PIN rule show?
    let pin = "80518";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  34. 34.🔀 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!
  35. 35.🔀 What does this battery rule show?
    let battery = 44;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  36. 36.🔀 Which badge does this quiz app show?
    let marks = 85;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  37. 37.🔀 What does this battery rule show?
    let battery = 26;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  38. 38.🔀 What does this PIN rule show?
    let pin = "176";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  39. 39.🔀 What does this battery rule show?
    let battery = 40;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  40. 40.🔀 What does this PIN rule show?
    let pin = "6540";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits

Answer key

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

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