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 if / else let an app do? (a) draw a screen (b) pick one of two actions (c) save a photo (d) repeat forever
- 2.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) !== (d) =
-
3.🔀 Which badge does this quiz app show?
let marks = 82;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
4.🔀 What does this PIN rule show?
let pin = "6469";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
5.🔀 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! -
6.🔀 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! -
7.🔀 What does this battery rule show?
let battery = 93;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
8.🔀 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) Gold (b) Bronze (c) Silver -
9.🔀 What number does this shop app show?
let total = 610;
if (total > 500) {
total = total - 50;
}
show(total); -
10.🔀 What number does this shop app show?
let total = 730;
if (total > 500) {
total = total - 50;
}
show(total); - 11.🔀 What does >= mean? (a) less than (b) not equal (c) greater than or equal (d) smaller or equal
-
12.🔀 What does this battery rule show?
let battery = 32;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
13.🔀 What does this PIN rule show?
let pin = "42450";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
14.🔀 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! -
15.🔀 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! -
16.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 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) Silver (b) Bronze (c) Gold -
18.🔀 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! -
19.🔀 Which badge does this quiz app show?
let marks = 93;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
20.🔀 What does this PIN rule show?
let pin = "609";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
21.🔀 What does this battery rule show?
let battery = 26;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
22.🔀 What number does this shop app show?
let total = 410;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 What does this PIN rule show?
let pin = "678";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 24.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) never (d) always
-
25.🔀 What does this battery rule show?
let battery = 75;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 26.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) all of them (d) only one
-
27.🔀 What does this PIN rule show?
let pin = "3452";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What does this PIN rule show?
let pin = "954";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
29.🔀 What does this PIN rule show?
let pin = "53690";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
30.🔀 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! -
31.🔀 What does this battery rule show?
let battery = 83;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
32.🔀 What does this PIN rule show?
let pin = "26697";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
33.🔀 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! -
34.🔀 What does this battery rule show?
let battery = 60;
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 = 420;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this PIN rule show?
let pin = "48980";
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 = 72;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
38.🔀 What does this PIN rule show?
let pin = "19515";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
39.🔀 What number does this shop app show?
let total = 690;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What number does this shop app show?
let total = 860;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- pick one of two actions
- ===
- Gold
- PIN saved
- Ask a parent
- Welcome!
- Battery OK
- Bronze
- 560
- 680
- greater than or equal
- Battery OK
- Use 4 digits
- Welcome!
- Welcome!
- 310
- Bronze
- Ask a parent
- Gold
- Use 4 digits
- Battery OK
- 410
- Use 4 digits
- when the test is false
- Battery OK
- only one
- PIN saved
- Use 4 digits
- Use 4 digits
- Ask a parent
- Battery OK
- Use 4 digits
- Ask a parent
- Battery OK
- 420
- Use 4 digits
- Battery OK
- Use 4 digits
- 640
- 810
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students