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.🔀 Which badge does this quiz app show?
let marks = 96;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 2.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) two (d) all of them
-
3.🔀 What does this battery rule show?
let battery = 93;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
4.🔀 What does this PIN rule show?
let pin = "8338";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 5.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) always (d) never
-
6.🔀 What number does this shop app show?
let total = 250;
if (total > 500) {
total = total - 50;
}
show(total); - 7.🔀 What does >= mean? (a) greater than or equal (b) smaller or equal (c) less than (d) not equal
- 8.🔀 What does if / else let an app do? (a) save a photo (b) draw a screen (c) pick one of two actions (d) repeat forever
-
9.🔀 What does this battery rule show?
let battery = 13;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
10.🔀 What does this battery rule show?
let battery = 29;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
11.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 What does this PIN rule show?
let pin = "408";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); - 14.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) => (d) !==
-
15.🔀 What does this battery rule show?
let battery = 85;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
16.🔀 What does this battery rule show?
let battery = 3;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
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 sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
19.🔀 What does this battery rule show?
let battery = 80;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
20.🔀 What number does this shop app show?
let total = 610;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 Which badge does this quiz app show?
let marks = 89;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
22.🔀 What does this PIN rule show?
let pin = "60158";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
23.🔀 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 -
24.🔀 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! -
25.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
26.🔀 What does this battery rule show?
let battery = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
27.🔀 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) Gold (b) Bronze (c) Silver -
28.🔀 Which badge does this quiz app show?
let marks = 98;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
29.🔀 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) Bronze (b) Gold (c) Silver -
30.🔀 What does this battery rule show?
let battery = 92;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
31.🔀 Which badge does this quiz app show?
let marks = 51;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
32.🔀 What number does this shop app show?
let total = 890;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 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! -
34.🔀 What does this PIN rule show?
let pin = "774";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What number does this shop app show?
let total = 280;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 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 -
37.🔀 What does this PIN rule show?
let pin = "9538";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
38.🔀 What does this PIN rule show?
let pin = "1100";
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 = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
40.🔀 What does this PIN rule show?
let pin = "61785";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- Gold
- only one
- Battery OK
- PIN saved
- when the test is false
- 250
- greater than or equal
- pick one of two actions
- Low battery
- Battery OK
- 320
- Use 4 digits
- 260
- ===
- Battery OK
- Low battery
- Ask a parent
- Ask a parent
- Battery OK
- 560
- Gold
- Use 4 digits
- Ask a parent
- Welcome!
- Battery OK
- Low battery
- Gold
- Gold
- Bronze
- Battery OK
- Silver
- 840
- Welcome!
- Use 4 digits
- 280
- Low battery
- PIN saved
- PIN saved
- Welcome!
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students