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.🔀 When does the else part run? (a) when the test is false (b) never (c) when the test is true (d) always
-
2.🔀 What does this sign-up rule show?
let age = 8;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
3.🔀 Which badge does this quiz app show?
let marks = 71;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
4.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
5.🔀 What does this PIN rule show?
let pin = "130";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
6.🔀 What does this PIN rule show?
let pin = "4038";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 7.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) less than (d) smaller or equal
-
8.🔀 What does this PIN rule show?
let pin = "8525";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
9.🔀 What number does this shop app show?
let total = 730;
if (total > 500) {
total = total - 50;
}
show(total); - 10.🔀 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
-
11.🔀 What number does this shop app show?
let total = 790;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 What does this PIN rule show?
let pin = "432";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
13.🔀 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 -
14.🔀 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 -
15.🔀 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! -
16.🔀 What does this battery rule show?
let battery = 3;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 17.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
-
18.🔀 What number does this shop app show?
let total = 800;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 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! -
20.🔀 What number does this shop app show?
let total = 300;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 What does this battery rule show?
let battery = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 22.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) two (d) only one
-
23.🔀 What does this PIN rule show?
let pin = "5638";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
24.🔀 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 -
25.🔀 What does this battery rule show?
let battery = 25;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
26.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 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! -
28.🔀 Which badge does this quiz app show?
let marks = 81;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
29.🔀 What does this battery rule show?
let battery = 40;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
30.🔀 What does this battery rule show?
let battery = 26;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
31.🔀 What number does this shop app show?
let total = 770;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 What number does this shop app show?
let total = 370;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 Which badge does this quiz app show?
let marks = 68;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
34.🔀 What does this PIN rule show?
let pin = "933";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 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 -
36.🔀 What does this PIN rule show?
let pin = "229";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
37.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 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) Silver (b) Bronze (c) Gold -
39.🔀 What does this PIN rule show?
let pin = "6814";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
40.🔀 What does this battery rule show?
let battery = 74;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK
Answer key
- when the test is false
- Ask a parent
- Silver
- 340
- Use 4 digits
- PIN saved
- greater than or equal
- PIN saved
- 680
- pick one of two actions
- 740
- Use 4 digits
- Bronze
- Welcome!
- Welcome!
- Low battery
- ===
- 750
- Welcome!
- 300
- Low battery
- only one
- PIN saved
- Ask a parent
- Battery OK
- 780
- Ask a parent
- Gold
- Battery OK
- Battery OK
- 720
- 370
- Silver
- Use 4 digits
- Battery OK
- Use 4 digits
- 590
- Gold
- PIN saved
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students