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 number does this shop app show?
let total = 660;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 What does this PIN rule show?
let pin = "267";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
3.🔀 Which badge does this quiz app show?
let marks = 23;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze - 4.🔀 What does >= mean? (a) greater than or equal (b) not equal (c) smaller or equal (d) less than
- 5.🔀 When does the else part run? (a) always (b) when the test is false (c) when the test is true (d) never
- 6.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) !== (d) =
- 7.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) none (d) two
-
8.🔀 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 -
9.🔀 Which badge does this quiz app show?
let marks = 20;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
10.🔀 What does this PIN rule show?
let pin = "6644";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
11.🔀 What does this battery rule show?
let battery = 52;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
12.🔀 What does this PIN rule show?
let pin = "797";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 Which badge does this quiz app show?
let marks = 83;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
14.🔀 What does this PIN rule show?
let pin = "60608";
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 = "604";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
16.🔀 What does this PIN rule show?
let pin = "6679";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
17.🔀 What does this battery rule show?
let battery = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
18.🔀 Which badge does this quiz app show?
let marks = 90;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
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 PIN rule show?
let pin = "350";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 21.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) save a photo (d) pick one of two actions
-
22.🔀 What does this PIN rule show?
let pin = "2469";
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 = 5;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
24.🔀 What number does this shop app show?
let total = 200;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 What number does this shop app show?
let total = 860;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 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 -
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 battery rule show?
let battery = 45;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
29.🔀 Which badge does this quiz app show?
let marks = 100;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
30.🔀 What does this PIN rule show?
let pin = "2251";
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 = 25;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
32.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 What does this PIN rule show?
let pin = "98828";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
34.🔀 What number does this shop app show?
let total = 410;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 What number does this shop app show?
let total = 280;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What number does this shop app show?
let total = 400;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 What does this battery rule show?
let battery = 70;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
38.🔀 What does this PIN rule show?
let pin = "1316";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 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 -
40.🔀 What number does this shop app show?
let total = 760;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- 610
- Use 4 digits
- Bronze
- greater than or equal
- when the test is false
- ===
- only one
- Ask a parent
- Bronze
- PIN saved
- Battery OK
- Use 4 digits
- Gold
- Use 4 digits
- Use 4 digits
- PIN saved
- Low battery
- Gold
- Welcome!
- Use 4 digits
- pick one of two actions
- PIN saved
- Low battery
- 200
- 810
- Low battery
- Welcome!
- Battery OK
- Gold
- PIN saved
- Battery OK
- 380
- Use 4 digits
- 410
- 280
- 400
- Battery OK
- PIN saved
- Welcome!
- 710
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students