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 PIN rule show?
let pin = "50191";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
2.🔀 What does this PIN rule show?
let pin = "1974";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 3.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
-
4.🔀 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! -
5.🔀 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! -
6.🔀 What does this battery rule show?
let battery = 23;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
7.🔀 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) Gold (c) Bronze -
8.🔀 What does this battery rule show?
let battery = 71;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
9.🔀 What does this PIN rule show?
let pin = "712";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 10.🔀 What does >= mean? (a) greater than or equal (b) smaller or equal (c) less than (d) not equal
-
11.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 Which badge does this quiz app show?
let marks = 25;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
13.🔀 What number does this shop app show?
let total = 300;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 Which badge does this quiz app show?
let marks = 40;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze - 15.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) all of them (d) only one
-
16.🔀 What does this PIN rule show?
let pin = "516";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
17.🔀 What number does this shop app show?
let total = 480;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 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 -
20.🔀 What number does this shop app show?
let total = 740;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 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 -
22.🔀 What does this PIN rule show?
let pin = "305";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
23.🔀 What does this PIN rule show?
let pin = "160";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
24.🔀 Which badge does this quiz app show?
let marks = 96;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold - 25.🔀 What does if / else let an app do? (a) draw a screen (b) pick one of two actions (c) repeat forever (d) save a photo
-
26.🔀 What does this PIN rule show?
let pin = "1917";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
27.🔀 What does this battery rule show?
let battery = 36;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
28.🔀 What does this battery rule show?
let battery = 96;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
29.🔀 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 -
30.🔀 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 -
31.🔀 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! -
32.🔀 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) Silver (b) Bronze (c) Gold - 33.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) === (d) =>
-
34.🔀 What does this PIN rule show?
let pin = "611";
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 = 49;
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 = "3509";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
37.🔀 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 -
38.🔀 What does this battery rule show?
let battery = 27;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
39.🔀 What number does this shop app show?
let total = 500;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this battery rule show?
let battery = 42;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- Use 4 digits
- PIN saved
- when the test is false
- Ask a parent
- Ask a parent
- Battery OK
- Gold
- Battery OK
- Use 4 digits
- greater than or equal
- 700
- Bronze
- 300
- Bronze
- only one
- Use 4 digits
- 480
- 260
- Low battery
- 690
- Ask a parent
- Use 4 digits
- Use 4 digits
- Gold
- pick one of two actions
- PIN saved
- Battery OK
- Battery OK
- Gold
- Battery OK
- Ask a parent
- Silver
- ===
- Use 4 digits
- Battery OK
- PIN saved
- Battery OK
- Battery OK
- 500
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students