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 = 43;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 2.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) repeat forever (d) draw a screen
- 3.🔀 When does the else part run? (a) never (b) when the test is false (c) when the test is true (d) always
-
4.🔀 What number does this shop app show?
let total = 590;
if (total > 500) {
total = total - 50;
}
show(total); -
5.🔀 What does this PIN rule show?
let pin = "76223";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
6.🔀 Which badge does this quiz app show?
let marks = 39;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
7.🔀 What does this sign-up rule show?
let age = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
8.🔀 What does this battery rule show?
let battery = 33;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
9.🔀 What does this battery rule show?
let battery = 30;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
10.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
11.🔀 What does this battery rule show?
let battery = 31;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 12.🔀 With if / else if / else, how many parts run? (a) none (b) only one (c) all of them (d) two
-
13.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 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 - 15.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) !== (c) === (d) =
-
16.🔀 What number does this shop app show?
let total = 440;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What does this PIN rule show?
let pin = "39122";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
18.🔀 What does this PIN rule show?
let pin = "35562";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
19.🔀 What number does this shop app show?
let total = 690;
if (total > 500) {
total = total - 50;
}
show(total); -
20.🔀 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 -
21.🔀 What does this battery rule show?
let battery = 89;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
22.🔀 What number does this shop app show?
let total = 700;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 What number does this shop app show?
let total = 390;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 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 -
25.🔀 Which badge does this quiz app show?
let marks = 36;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
26.🔀 What does this battery rule show?
let battery = 27;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
27.🔀 Which badge does this quiz app show?
let marks = 85;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
28.🔀 What does this battery rule show?
let battery = 10;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
29.🔀 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! -
30.🔀 What number does this shop app show?
let total = 570;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 What number does this shop app show?
let total = 610;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 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! -
33.🔀 What does this PIN rule show?
let pin = "4466";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
34.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 What does this sign-up rule show?
let age = 13;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent - 36.🔀 What does >= mean? (a) less than (b) greater than or equal (c) smaller or equal (d) not equal
-
37.🔀 What does this battery rule show?
let battery = 37;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
38.🔀 Which badge does this quiz app show?
let marks = 22;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
39.🔀 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 -
40.🔀 What does this PIN rule show?
let pin = "484";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- Battery OK
- pick one of two actions
- when the test is false
- 540
- Use 4 digits
- Bronze
- Ask a parent
- Battery OK
- Battery OK
- 230
- Battery OK
- only one
- 700
- Battery OK
- ===
- 440
- Use 4 digits
- Use 4 digits
- 640
- Welcome!
- Battery OK
- 650
- 390
- Low battery
- Bronze
- Battery OK
- Gold
- Low battery
- Ask a parent
- 520
- 560
- Welcome!
- PIN saved
- 340
- Welcome!
- greater than or equal
- Battery OK
- Bronze
- Ask a parent
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students