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.🔀 What number does this shop app show?
let total = 820;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 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! - 3.🔀 What does if / else let an app do? (a) draw a screen (b) pick one of two actions (c) save a photo (d) repeat forever
-
4.🔀 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 -
5.🔀 What does this battery rule show?
let battery = 92;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
6.🔀 What number does this shop app show?
let total = 360;
if (total > 500) {
total = total - 50;
}
show(total); -
7.🔀 What number does this shop app show?
let total = 280;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 What does this battery rule show?
let battery = 21;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 9.🔀 With if / else if / else, how many parts run? (a) two (b) all of them (c) none (d) only one
-
10.🔀 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! - 11.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) => (c) === (d) !==
-
12.🔀 What does this battery rule show?
let battery = 55;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 13.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) always (d) never
-
14.🔀 What does this PIN rule show?
let pin = "98499";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
15.🔀 Which badge does this quiz app show?
let marks = 53;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
16.🔀 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 -
17.🔀 What number does this shop app show?
let total = 670;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 460;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 What does this PIN rule show?
let pin = "2460";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
20.🔀 What does this battery rule show?
let battery = 54;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
21.🔀 What does this PIN rule show?
let pin = "664";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
22.🔀 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! -
23.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 What number does this shop app show?
let total = 860;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 What does this PIN rule show?
let pin = "1934";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
26.🔀 What does this PIN rule show?
let pin = "33767";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
27.🔀 What number does this shop app show?
let total = 700;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What does this PIN rule show?
let pin = "3414";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
29.🔀 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 -
30.🔀 What does this PIN rule show?
let pin = "799";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 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 -
32.🔀 What does this battery rule show?
let battery = 57;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
33.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
34.🔀 What does this battery rule show?
let battery = 9;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
35.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this PIN rule show?
let pin = "674";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
37.🔀 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) Silver (b) Bronze (c) Gold -
38.🔀 Which badge does this quiz app show?
let marks = 35;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
39.🔀 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 -
40.🔀 What does this PIN rule show?
let pin = "2037";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved
Answer key
- 770
- Ask a parent
- pick one of two actions
- Ask a parent
- Battery OK
- 360
- 280
- Battery OK
- only one
- Ask a parent
- ===
- Battery OK
- when the test is false
- Use 4 digits
- Silver
- Welcome!
- 620
- 460
- PIN saved
- Battery OK
- Use 4 digits
- Welcome!
- 510
- 810
- PIN saved
- Use 4 digits
- 650
- PIN saved
- Battery OK
- Use 4 digits
- Battery OK
- Battery OK
- Battery OK
- Low battery
- 260
- Use 4 digits
- Gold
- Bronze
- Ask a parent
- PIN saved
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students