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 = "1538";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
2.🔀 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! - 3.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) = (d) !==
-
4.🔀 What does this PIN rule show?
let pin = "23806";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
5.🔀 What number does this shop app show?
let total = 740;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What does this battery rule show?
let battery = 11;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 7.🔀 What does >= mean? (a) not equal (b) less than (c) smaller or equal (d) greater than or equal
- 8.🔀 When does the else part run? (a) always (b) never (c) when the test is false (d) when the test is true
-
9.🔀 Which badge does this quiz app show?
let marks = 80;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
10.🔀 What number does this shop app show?
let total = 480;
if (total > 500) {
total = total - 50;
}
show(total); -
11.🔀 What does this PIN rule show?
let pin = "83879";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 12.🔀 What does if / else let an app do? (a) repeat forever (b) save a photo (c) draw a screen (d) pick one of two actions
-
13.🔀 Which badge does this quiz app show?
let marks = 59;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
14.🔀 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 -
15.🔀 What does this PIN rule show?
let pin = "69763";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 16.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) all of them (d) only one
-
17.🔀 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! -
18.🔀 What does this PIN rule show?
let pin = "1284";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
19.🔀 What does this PIN rule show?
let pin = "96338";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
20.🔀 What does this sign-up rule show?
let age = 14;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
21.🔀 What number does this shop app show?
let total = 550;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What does this PIN rule show?
let pin = "44610";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
23.🔀 What does this battery rule show?
let battery = 12;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
24.🔀 What does this PIN rule show?
let pin = "3221";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
25.🔀 What does this battery rule show?
let battery = 70;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
26.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 Which badge does this quiz app show?
let marks = 57;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
28.🔀 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 -
29.🔀 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! -
30.🔀 What number does this shop app show?
let total = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 What number does this shop app show?
let total = 510;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 What does this battery rule show?
let battery = 3;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
33.🔀 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) Gold (b) Bronze (c) Silver -
34.🔀 What does this battery rule show?
let battery = 99;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
35.🔀 What number does this shop app show?
let total = 450;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this battery rule show?
let battery = 92;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
37.🔀 Which badge does this quiz app show?
let marks = 63;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
38.🔀 What number does this shop app show?
let total = 620;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 Which badge does this quiz app show?
let marks = 75;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
40.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- PIN saved
- Welcome!
- ===
- Use 4 digits
- 690
- Low battery
- greater than or equal
- when the test is false
- Gold
- 480
- Use 4 digits
- pick one of two actions
- Silver
- Welcome!
- Use 4 digits
- only one
- Ask a parent
- PIN saved
- Use 4 digits
- Welcome!
- 500
- Use 4 digits
- Low battery
- PIN saved
- Battery OK
- 800
- Silver
- Ask a parent
- Ask a parent
- 210
- 460
- Low battery
- Silver
- Battery OK
- 450
- Battery OK
- Silver
- 570
- Silver
- 590
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students