← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 11 · 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 this sign-up rule show?
    let age = 9;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  2. 2.🔀 What number does this shop app show?
    let total = 550;
    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) Ask a parent (b) Welcome!
  4. 4.🔀 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
  5. 5.🔀 What does this battery rule show?
    let battery = 42;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  6. 6.🔀 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
  7. 7.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
  8. 8.🔀 What does this battery rule show?
    let battery = 1;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  9. 9.🔀 What does this PIN rule show?
    let pin = "3594";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  10. 10.🔀 What number does this shop app show?
    let total = 530;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  11. 11.🔀 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) Silver (c) Bronze
  12. 12.🔀 What does this PIN rule show?
    let pin = "693";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  13. 13.🔀 Which badge does this quiz app show?
    let marks = 26;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  14. 14.🔀 What number does this shop app show?
    let total = 620;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  15. 15.🔀 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!
  16. 16.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) pick one of two actions (d) draw a screen
  17. 17.🔀 What number does this shop app show?
    let total = 250;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What number does this shop app show?
    let total = 430;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  19. 19.🔀 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
  20. 20.🔀 Which badge does this quiz app show?
    let marks = 45;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  21. 21.🔀 What number does this shop app show?
    let total = 220;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  22. 22.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) => (c) === (d) !==
  23. 23.🔀 Which badge does this quiz app show?
    let marks = 31;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  24. 24.🔀 What does this battery rule show?
    let battery = 51;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  25. 25.🔀 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!
  26. 26.🔀 What does this PIN rule show?
    let pin = "6652";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  27. 27.🔀 What does >= mean? (a) less than (b) not equal (c) smaller or equal (d) greater than or equal
  28. 28.🔀 What does this battery rule show?
    let battery = 73;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  29. 29.🔀 What does this PIN rule show?
    let pin = "26603";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  30. 30.🔀 What number does this shop app show?
    let total = 330;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 What does this battery rule show?
    let battery = 92;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  32. 32.🔀 What does this PIN rule show?
    let pin = "73818";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  33. 33.🔀 What number does this shop app show?
    let total = 850;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  34. 34.🔀 What number does this shop app show?
    let total = 510;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 What number does this shop app show?
    let total = 400;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this battery rule show?
    let battery = 39;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  37. 37.🔀 What does this PIN rule show?
    let pin = "64437";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  38. 38.🔀 Which badge does this quiz app show?
    let marks = 68;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  39. 39.🔀 What does this sign-up rule show?
    let age = 8;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  40. 40.🔀 What does this sign-up rule show?
    let age = 14;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent

Answer key

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

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