App Dev Worksheet: If Else Rules
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.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) === (d) !==
-
2.🔀 What does this PIN rule show?
let pin = "15518";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 3.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) two (d) none
-
4.🔀 What does this PIN rule show?
let pin = "1332";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 5.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
-
6.🔀 What does this battery rule show?
let battery = 66;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
7.🔀 What does this battery rule show?
let battery = 19;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 8.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) repeat forever (d) pick one of two actions
-
9.🔀 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! -
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.🔀 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) Silver (b) Bronze (c) Gold -
12.🔀 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 -
13.🔀 What number does this shop app show?
let total = 410;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What does this PIN rule show?
let pin = "5382";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
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.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What does this sign-up rule show?
let age = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
18.🔀 Which badge does this quiz app show?
let marks = 33;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
19.🔀 What does this battery rule show?
let battery = 18;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
20.🔀 Which badge does this quiz app show?
let marks = 42;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
21.🔀 What number does this shop app show?
let total = 480;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 What does this sign-up rule show?
let age = 9;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
24.🔀 What does this PIN rule show?
let pin = "67120";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
25.🔀 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 -
26.🔀 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 -
27.🔀 What number does this shop app show?
let total = 280;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What does this battery rule show?
let battery = 89;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
29.🔀 What number does this shop app show?
let total = 760;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 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 -
31.🔀 What does this PIN rule show?
let pin = "72386";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
32.🔀 What does this battery rule show?
let battery = 87;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
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) Bronze (b) Silver (c) Gold -
34.🔀 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! -
35.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this battery rule show?
let battery = 29;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
37.🔀 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 -
38.🔀 What does this battery rule show?
let battery = 88;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
39.🔀 What does this PIN rule show?
let pin = "489";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
40.🔀 What does this PIN rule show?
let pin = "66850";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- ===
- Use 4 digits
- only one
- PIN saved
- when the test is false
- Battery OK
- Low battery
- pick one of two actions
- Welcome!
- Battery OK
- Bronze
- Gold
- 410
- PIN saved
- Ask a parent
- 590
- Welcome!
- Bronze
- Low battery
- Bronze
- 480
- 510
- Ask a parent
- Use 4 digits
- Ask a parent
- Battery OK
- 280
- Battery OK
- 710
- Welcome!
- Use 4 digits
- Battery OK
- Gold
- Welcome!
- 340
- Battery OK
- Ask a parent
- Battery OK
- Use 4 digits
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students