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 = 8;
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) draw a screen (b) repeat forever (c) pick one of two actions (d) save a photo
-
3.🔀 Which badge does this quiz app show?
let marks = 95;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
4.🔀 What does this battery rule show?
let battery = 9;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
5.🔀 What does this battery rule show?
let battery = 11;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
6.🔀 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 - 7.🔀 With if / else if / else, how many parts run? (a) all of them (b) none (c) two (d) only one
-
8.🔀 What number does this shop app show?
let total = 900;
if (total > 500) {
total = total - 50;
}
show(total); -
9.🔀 What does this battery rule show?
let battery = 34;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
10.🔀 What does this PIN rule show?
let pin = "856";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 11.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) === (d) !==
-
12.🔀 What number does this shop app show?
let total = 630;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 What does this PIN rule show?
let pin = "7383";
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 = 880;
if (total > 500) {
total = total - 50;
}
show(total); - 15.🔀 When does the else part run? (a) never (b) always (c) when the test is false (d) when the test is true
-
16.🔀 What does this battery rule show?
let battery = 97;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
17.🔀 Which badge does this quiz app show?
let marks = 50;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
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.🔀 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 -
20.🔀 What does this battery rule show?
let battery = 2;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
21.🔀 Which badge does this quiz app show?
let marks = 58;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
22.🔀 What number does this shop app show?
let total = 510;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 Which badge does this quiz app show?
let marks = 54;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
24.🔀 Which badge does this quiz app show?
let marks = 72;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
25.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What number does this shop app show?
let total = 420;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What does this sign-up rule show?
let age = 9;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
28.🔀 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! -
29.🔀 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! -
30.🔀 What does this PIN rule show?
let pin = "169";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 What does this battery rule show?
let battery = 5;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
32.🔀 What does this PIN rule show?
let pin = "8312";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
33.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this PIN rule show?
let pin = "726";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What does this sign-up rule show?
let age = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
36.🔀 What does this PIN rule show?
let pin = "466";
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 = 22;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
38.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 Which badge does this quiz app show?
let marks = 32;
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 = 450;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- Low battery
- pick one of two actions
- Gold
- Low battery
- Low battery
- Ask a parent
- only one
- 850
- Battery OK
- Use 4 digits
- ===
- 580
- PIN saved
- 830
- when the test is false
- Battery OK
- Silver
- Low battery
- Welcome!
- Low battery
- Silver
- 460
- Silver
- Silver
- 350
- 420
- Ask a parent
- Welcome!
- Ask a parent
- Use 4 digits
- Low battery
- PIN saved
- 780
- Use 4 digits
- Welcome!
- Use 4 digits
- Battery OK
- 230
- Bronze
- 450
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students