← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 53 · 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 = 61;
    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 = 820;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  3. 3.🔀 With if / else if / else, how many parts run? (a) all of them (b) none (c) only one (d) two
  4. 4.🔀 What does this battery rule show?
    let battery = 50;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  5. 5.🔀 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
  6. 6.🔀 What number does this shop app show?
    let total = 880;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  7. 7.🔀 What does this battery rule show?
    let battery = 15;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  8. 8.🔀 What number does this shop app show?
    let total = 300;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  9. 9.🔀 What does this battery rule show?
    let battery = 53;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  10. 10.🔀 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
  11. 11.🔀 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
  12. 12.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) === (c) => (d) =
  13. 13.🔀 What does this battery rule show?
    let battery = 9;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  14. 14.🔀 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
  15. 15.🔀 What does this battery rule show?
    let battery = 98;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  16. 16.🔀 What does this PIN rule show?
    let pin = "25455";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  17. 17.🔀 What number does this shop app show?
    let total = 200;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  18. 18.🔀 What number does this shop app show?
    let total = 330;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  19. 19.🔀 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!
  20. 20.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) always (d) never
  21. 21.🔀 What does this battery rule show?
    let battery = 21;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  22. 22.🔀 What does >= mean? (a) less than (b) greater than or equal (c) not equal (d) smaller or equal
  23. 23.🔀 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
  24. 24.🔀 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) Silver (b) Gold (c) Bronze
  25. 25.🔀 What does this battery rule show?
    let battery = 6;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  26. 26.🔀 What does this sign-up rule show?
    let age = 13;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  27. 27.🔀 What does this PIN rule show?
    let pin = "585";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  28. 28.🔀 What does this PIN rule show?
    let pin = "587";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  29. 29.🔀 What number does this shop app show?
    let total = 670;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  30. 30.🔀 What does this PIN rule show?
    let pin = "1156";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  31. 31.🔀 What does this battery rule show?
    let battery = 86;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  32. 32.🔀 What number does this shop app show?
    let total = 550;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  33. 33.🔀 What does this battery rule show?
    let battery = 25;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  34. 34.🔀 What does this PIN rule show?
    let pin = "4251";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  35. 35.🔀 What number does this shop app show?
    let total = 860;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 What does this PIN rule show?
    let pin = "93803";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  37. 37.🔀 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!
  38. 38.🔀 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
  39. 39.🔀 What number does this shop app show?
    let total = 290;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  40. 40.🔀 What number does this shop app show?
    let total = 310;
    if (total > 500) {
      total = total - 50;
    }
    show(total);

Answer key

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

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