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