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 = 61;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
2.🔀 What number does this shop app show?
let total = 820;
if (total > 500) {
total = total - 50;
}
show(total); - 3.🔀 With if / else if / else, how many parts run? (a) all of them (b) none (c) only one (d) two
-
4.🔀 What does this battery rule show?
let battery = 50;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
5.🔀 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 -
6.🔀 What number does this shop app show?
let total = 880;
if (total > 500) {
total = total - 50;
}
show(total); -
7.🔀 What does this battery rule show?
let battery = 15;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
8.🔀 What number does this shop app show?
let total = 300;
if (total > 500) {
total = total - 50;
}
show(total); -
9.🔀 What does this battery rule show?
let battery = 53;
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 = 26;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
11.🔀 What does this battery rule show?
let battery = 5;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 12.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) === (c) => (d) =
-
13.🔀 What does this battery rule show?
let battery = 9;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
14.🔀 Which badge does this quiz app show?
let marks = 70;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
15.🔀 What does this battery rule show?
let battery = 98;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
16.🔀 What does this PIN rule show?
let pin = "25455";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
17.🔀 What number does this shop app show?
let total = 200;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 330;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 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! - 20.🔀 When does the else part run? (a) when the test is true (b) when the test is false (c) always (d) never
-
21.🔀 What does this battery rule show?
let battery = 21;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 22.🔀 What does >= mean? (a) less than (b) greater than or equal (c) not equal (d) smaller or equal
- 23.🔀 What does if / else let an app do? (a) repeat forever (b) draw a screen (c) save a photo (d) pick one of two actions
-
24.🔀 Which badge does this quiz app show?
let marks = 97;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
25.🔀 What does this battery rule show?
let battery = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
26.🔀 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 -
27.🔀 What does this PIN rule show?
let pin = "585";
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 = "587";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
29.🔀 What number does this shop app show?
let total = 670;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What does this PIN rule show?
let pin = "1156";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
31.🔀 What does this battery rule show?
let battery = 86;
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 = 550;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 What does this battery rule show?
let battery = 25;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
34.🔀 What does this PIN rule show?
let pin = "4251";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What number does this shop app show?
let total = 860;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this PIN rule show?
let pin = "93803";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
37.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
38.🔀 What does this battery rule show?
let battery = 76;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
39.🔀 What number does this shop app show?
let total = 290;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- Silver
- 770
- only one
- Battery OK
- Welcome!
- 830
- Low battery
- 300
- Battery OK
- Battery OK
- Low battery
- ===
- Low battery
- Silver
- Battery OK
- Use 4 digits
- 200
- 330
- Welcome!
- when the test is false
- Battery OK
- greater than or equal
- pick one of two actions
- Gold
- Low battery
- Welcome!
- Use 4 digits
- Use 4 digits
- 620
- PIN saved
- Battery OK
- 500
- Battery OK
- PIN saved
- 810
- Use 4 digits
- Ask a parent
- Battery OK
- 290
- 310
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students