← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 1 · 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.🔀 Which badge does this quiz app show?
    let marks = 28;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  2. 2.🔀 What number does this shop app show?
    let total = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  3. 3.🔀 What number does this shop app show?
    let total = 290;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  4. 4.🔀 When does the else part run? (a) always (b) when the test is true (c) never (d) when the test is false
  5. 5.🔀 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) Bronze (b) Silver (c) Gold
  6. 6.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
  7. 7.🔀 What number does this shop app show?
    let total = 590;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 Which badge does this quiz app show?
    let marks = 58;
    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 = 400;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  10. 10.🔀 What does this battery rule show?
    let battery = 72;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  11. 11.🔀 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!
  12. 12.🔀 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!
  13. 13.🔀 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
  14. 14.🔀 What does >= mean? (a) smaller or equal (b) less than (c) not equal (d) greater than or equal
  15. 15.🔀 What does this PIN rule show?
    let pin = "5254";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  16. 16.🔀 What number does this shop app show?
    let total = 360;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  17. 17.🔀 What does this battery rule show?
    let battery = 24;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  18. 18.🔀 What does this PIN rule show?
    let pin = "23113";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  19. 19.🔀 What does this PIN rule show?
    let pin = "1846";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  20. 20.🔀 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
  21. 21.🔀 What does this battery rule show?
    let battery = 23;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  22. 22.🔀 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) Bronze (b) Silver (c) Gold
  23. 23.🔀 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
  24. 24.🔀 What number does this shop app show?
    let total = 220;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  25. 25.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) pick one of two actions (d) save a photo
  26. 26.🔀 What does this PIN rule show?
    let pin = "4826";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  27. 27.🔀 What number does this shop app show?
    let total = 820;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 What does this battery rule show?
    let battery = 50;
    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 = "542";
    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 = 280;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 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
  32. 32.🔀 What number does this shop app show?
    let total = 230;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 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!
  34. 34.🔀 What number does this shop app show?
    let total = 880;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  35. 35.🔀 Which badge does this quiz app show?
    let marks = 84;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  36. 36.🔀 What number does this shop app show?
    let total = 200;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  37. 37.🔀 Which badge does this quiz app show?
    let marks = 22;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  38. 38.🔀 What does this PIN rule show?
    let pin = "9279";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  39. 39.🔀 Which badge does this quiz app show?
    let marks = 20;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  40. 40.🔀 What does this battery rule show?
    let battery = 54;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK

Answer key

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

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