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 = "311";
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 = "4097";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
3.🔀 What does this PIN rule show?
let pin = "2156";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
4.🔀 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 -
5.🔀 What does this PIN rule show?
let pin = "8146";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
6.🔀 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 - 7.🔀 What does >= mean? (a) greater than or equal (b) less than (c) not equal (d) smaller or equal
- 8.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) !== (c) = (d) ===
-
9.🔀 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 -
10.🔀 What does this PIN rule show?
let pin = "1823";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
11.🔀 What does this battery rule show?
let battery = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
12.🔀 What does this PIN rule show?
let pin = "1035";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 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! -
14.🔀 What number does this shop app show?
let total = 200;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
16.🔀 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) Silver (b) Gold (c) Bronze -
17.🔀 What does this PIN rule show?
let pin = "63710";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
18.🔀 What does this battery rule show?
let battery = 81;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
19.🔀 What does this PIN rule show?
let pin = "854";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
20.🔀 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! -
21.🔀 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 -
22.🔀 What number does this shop app show?
let total = 390;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 Which badge does this quiz app show?
let marks = 92;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
24.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); - 25.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) always (d) never
-
26.🔀 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 -
27.🔀 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 -
28.🔀 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! -
29.🔀 What does this battery rule show?
let battery = 90;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
30.🔀 What does this battery rule show?
let battery = 44;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
31.🔀 What does this PIN rule show?
let pin = "662";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
32.🔀 What does this PIN rule show?
let pin = "87620";
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 = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 Which badge does this quiz app show?
let marks = 81;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver - 35.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) two (d) all of them
-
36.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 What does this battery rule show?
let battery = 62;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 38.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
-
39.🔀 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 -
40.🔀 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
Answer key
- Use 4 digits
- PIN saved
- PIN saved
- Welcome!
- PIN saved
- Welcome!
- greater than or equal
- ===
- Ask a parent
- PIN saved
- Low battery
- PIN saved
- Welcome!
- 200
- 350
- Bronze
- Use 4 digits
- Battery OK
- Use 4 digits
- Ask a parent
- Battery OK
- 390
- Gold
- 380
- when the test is false
- Ask a parent
- Welcome!
- Ask a parent
- Battery OK
- Battery OK
- Use 4 digits
- Use 4 digits
- 210
- Gold
- only one
- 510
- Battery OK
- pick one of two actions
- Low battery
- Gold
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students