← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 6 · 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.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) all of them (d) none
  2. 2.🔀 What number does this shop app show?
    let total = 250;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  3. 3.🔀 What does this PIN rule show?
    let pin = "268";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 What does this PIN rule show?
    let pin = "679";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  5. 5.🔀 What does this PIN rule show?
    let pin = "8886";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  6. 6.🔀 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
  7. 7.🔀 What number does this shop app show?
    let total = 470;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 What does this PIN rule show?
    let pin = "1396";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  9. 9.🔀 What does this sign-up rule show?
    let age = 11;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  10. 10.🔀 Which badge does this quiz app show?
    let marks = 88;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Gold (c) Bronze
  11. 11.🔀 Which badge does this quiz app show?
    let marks = 36;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  12. 12.🔀 What does if / else let an app do? (a) pick one of two actions (b) draw a screen (c) repeat forever (d) save a photo
  13. 13.🔀 What number does this shop app show?
    let total = 400;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 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
  15. 15.🔀 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!
  16. 16.🔀 What does this PIN rule show?
    let pin = "39560";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  17. 17.🔀 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!
  18. 18.🔀 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
  19. 19.🔀 What number does this shop app show?
    let total = 260;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 What does >= mean? (a) not equal (b) less than (c) greater than or equal (d) smaller or equal
  21. 21.🔀 What does this battery rule show?
    let battery = 76;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  22. 22.🔀 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
  23. 23.🔀 What number does this shop app show?
    let total = 240;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  24. 24.🔀 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
  25. 25.🔀 What does this PIN rule show?
    let pin = "5229";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  26. 26.🔀 Which badge does this quiz app show?
    let marks = 49;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  27. 27.🔀 What number does this shop app show?
    let total = 890;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  28. 28.🔀 Which badge does this quiz app show?
    let marks = 99;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Bronze (b) Silver (c) Gold
  29. 29.🔀 When does the else part run? (a) always (b) when the test is false (c) never (d) when the test is true
  30. 30.🔀 What number does this shop app show?
    let total = 750;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  31. 31.🔀 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!
  32. 32.🔀 What does this battery rule show?
    let battery = 96;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  33. 33.🔀 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!
  34. 34.🔀 What does this PIN rule show?
    let pin = "364";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  35. 35.🔀 What number does this shop app show?
    let total = 210;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  36. 36.🔀 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) Bronze (b) Silver (c) Gold
  37. 37.🔀 What does this battery rule show?
    let battery = 48;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  38. 38.🔀 What does this battery rule show?
    let battery = 79;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  39. 39.🔀 What does this PIN rule show?
    let pin = "826";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) PIN saved (b) Use 4 digits
  40. 40.🔀 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

Answer key

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

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