← if / else: app rules lesson New set →

App Dev Worksheet: If Else Rules

App development lesson 18: if / else: app rules · Set 23 · 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 number does this shop app show?
    let total = 620;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  2. 2.🔀 When does the else part run? (a) when the test is false (b) never (c) when the test is true (d) always
  3. 3.🔀 What does this PIN rule show?
    let pin = "3178";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  4. 4.🔀 With if / else if / else, how many parts run? (a) only one (b) two (c) all of them (d) none
  5. 5.🔀 What does this PIN rule show?
    let pin = "4311";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  6. 6.🔀 Which badge does this quiz app show?
    let marks = 38;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  7. 7.🔀 What number does this shop app show?
    let total = 510;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  8. 8.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) => (c) = (d) ===
  9. 9.🔀 Which badge does this quiz app show?
    let marks = 82;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  10. 10.🔀 What does if / else let an app do? (a) save a photo (b) draw a screen (c) repeat forever (d) pick one of two actions
  11. 11.🔀 What does this sign-up rule show?
    let age = 12;
    if (age >= 13) {
      show("Welcome!");
    } else {
      show("Ask a parent");
    }
    (a) Welcome! (b) Ask a parent
  12. 12.🔀 What number does this shop app show?
    let total = 670;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  13. 13.🔀 What number does this shop app show?
    let total = 370;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  14. 14.🔀 What number does this shop app show?
    let total = 540;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  15. 15.🔀 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
  16. 16.🔀 What number does this shop app show?
    let total = 550;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  17. 17.🔀 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
  18. 18.🔀 What does this PIN rule show?
    let pin = "916";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  19. 19.🔀 What number does this shop app show?
    let total = 490;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  20. 20.🔀 What does this PIN rule show?
    let pin = "469";
    if (pin.length === 4) {
      show("PIN saved");
    } else {
      show("Use 4 digits");
    }
    (a) Use 4 digits (b) PIN saved
  21. 21.🔀 What does this battery rule show?
    let battery = 82;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Low battery (b) Battery OK
  22. 22.🔀 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) Gold (c) Bronze
  23. 23.🔀 What number does this shop app show?
    let total = 760;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  24. 24.🔀 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
  25. 25.🔀 What does this battery rule show?
    let battery = 97;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  26. 26.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
  27. 27.🔀 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
  28. 28.🔀 What number does this shop app show?
    let total = 610;
    if (total > 500) {
      total = total - 50;
    }
    show(total);
  29. 29.🔀 What does this battery rule show?
    let battery = 68;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  30. 30.🔀 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) Silver (b) Bronze (c) Gold
  31. 31.🔀 What does this battery rule show?
    let battery = 25;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  32. 32.🔀 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
  33. 33.🔀 Which badge does this quiz app show?
    let marks = 93;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Bronze (c) Silver
  34. 34.🔀 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!
  35. 35.🔀 Which badge does this quiz app show?
    let marks = 21;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze
  36. 36.🔀 Which badge does this quiz app show?
    let marks = 62;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Silver (b) Bronze (c) Gold
  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) Gold (b) Bronze (c) Silver
  38. 38.🔀 What does this battery rule show?
    let battery = 59;
    if (battery < 20) {
      show("Low battery");
    } else {
      show("Battery OK");
    }
    (a) Battery OK (b) Low battery
  39. 39.🔀 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!
  40. 40.🔀 Which badge does this quiz app show?
    let marks = 89;
    if (marks >= 80) {
      show("Gold");
    } else if (marks >= 50) {
      show("Silver");
    } else {
      show("Bronze");
    }
    (a) Gold (b) Silver (c) Bronze

Answer key

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

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