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 sign-up rule show?
let age = 8;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
2.🔀 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 -
3.🔀 What does this PIN rule show?
let pin = "25734";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
4.🔀 What does this battery rule show?
let battery = 15;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
5.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What number does this shop app show?
let total = 290;
if (total > 500) {
total = total - 50;
}
show(total); -
7.🔀 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 -
8.🔀 What does this PIN rule show?
let pin = "7598";
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 = 470;
if (total > 500) {
total = total - 50;
}
show(total); -
10.🔀 What number does this shop app show?
let total = 530;
if (total > 500) {
total = total - 50;
}
show(total); -
11.🔀 Which badge does this quiz app show?
let marks = 79;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze - 12.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) none (d) all of them
-
13.🔀 What does this PIN rule show?
let pin = "3105";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
14.🔀 What number does this shop app show?
let total = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 What does this PIN rule show?
let pin = "854";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
16.🔀 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 -
17.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What does this battery rule show?
let battery = 4;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 19.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) !== (c) === (d) =
-
20.🔀 What does this PIN rule show?
let pin = "45376";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 21.🔀 When does the else part run? (a) when the test is true (b) always (c) when the test is false (d) never
-
22.🔀 What number does this shop app show?
let total = 790;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 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! -
24.🔀 What number does this shop app show?
let total = 460;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 What does this battery rule show?
let battery = 45;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 26.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) greater than or equal (d) less than
-
27.🔀 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 -
28.🔀 Which badge does this quiz app show?
let marks = 75;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
29.🔀 What does this PIN rule show?
let pin = "878";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
30.🔀 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 -
31.🔀 What number does this shop app show?
let total = 900;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 What does this PIN rule show?
let pin = "85681";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
33.🔀 What number does this shop app show?
let total = 500;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this battery rule show?
let battery = 55;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
35.🔀 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 -
36.🔀 What does this battery rule show?
let battery = 77;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 37.🔀 What does if / else let an app do? (a) save a photo (b) draw a screen (c) pick one of two actions (d) repeat forever
-
38.🔀 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! -
39.🔀 What does this battery rule show?
let battery = 18;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
40.🔀 What does this PIN rule show?
let pin = "90182";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- Ask a parent
- Battery OK
- Use 4 digits
- Low battery
- 310
- 290
- Ask a parent
- PIN saved
- 470
- 480
- Silver
- only one
- PIN saved
- 210
- Use 4 digits
- Low battery
- 590
- Low battery
- ===
- Use 4 digits
- when the test is false
- 740
- Welcome!
- 460
- Battery OK
- greater than or equal
- Welcome!
- Silver
- Use 4 digits
- Welcome!
- 850
- Use 4 digits
- 500
- Battery OK
- Battery OK
- Battery OK
- pick one of two actions
- Ask a parent
- Low battery
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students