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 does this battery rule show?
let battery = 51;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 2.🔀 What does if / else let an app do? (a) save a photo (b) pick one of two actions (c) draw a screen (d) repeat forever
-
3.🔀 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 -
4.🔀 What does this battery rule show?
let battery = 7;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
5.🔀 What does this PIN rule show?
let pin = "4225";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
6.🔀 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 -
7.🔀 What does this PIN rule show?
let pin = "64306";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
8.🔀 Which badge does this quiz app show?
let marks = 69;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 9.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) => (d) ===
-
10.🔀 Which badge does this quiz app show?
let marks = 54;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
11.🔀 What does this PIN rule show?
let pin = "628";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
12.🔀 What does this PIN rule show?
let pin = "470";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 13.🔀 When does the else part run? (a) never (b) always (c) when the test is true (d) when the test is false
-
14.🔀 What number does this shop app show?
let total = 460;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 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 -
16.🔀 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 -
17.🔀 What number does this shop app show?
let total = 900;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 570;
if (total > 500) {
total = total - 50;
}
show(total); -
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.🔀 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! -
21.🔀 What number does this shop app show?
let total = 890;
if (total > 500) {
total = total - 50;
}
show(total); - 22.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) only one (d) all of them
-
23.🔀 What does this PIN rule show?
let pin = "304";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
24.🔀 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! -
25.🔀 What does this PIN rule show?
let pin = "7567";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
26.🔀 What number does this shop app show?
let total = 680;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What number does this shop app show?
let total = 620;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What number does this shop app show?
let total = 740;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 What does this PIN rule show?
let pin = "52343";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
30.🔀 What does this battery rule show?
let battery = 1;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
31.🔀 What does this battery rule show?
let battery = 35;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
32.🔀 What number does this shop app show?
let total = 480;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 What number does this shop app show?
let total = 410;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 Which badge does this quiz app show?
let marks = 51;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
36.🔀 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) Gold (c) Silver -
37.🔀 What does this PIN rule show?
let pin = "116";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
38.🔀 Which badge does this quiz app show?
let marks = 31;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
39.🔀 What number does this shop app show?
let total = 490;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this battery rule show?
let battery = 93;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- Battery OK
- pick one of two actions
- Gold
- Low battery
- PIN saved
- Welcome!
- Use 4 digits
- Silver
- ===
- Silver
- Use 4 digits
- Use 4 digits
- when the test is false
- 460
- Low battery
- Battery OK
- 850
- 520
- Welcome!
- Ask a parent
- 840
- only one
- Use 4 digits
- Welcome!
- PIN saved
- 630
- 570
- 690
- Use 4 digits
- Low battery
- Battery OK
- 480
- 410
- 590
- Silver
- Bronze
- Use 4 digits
- Bronze
- 490
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students