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