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 = "35861";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
2.🔀 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 -
3.🔀 What does this PIN rule show?
let pin = "580";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
4.🔀 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 -
5.🔀 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 - 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) none (b) all of them (c) two (d) only one
-
8.🔀 What does this battery rule show?
let battery = 48;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 9.🔀 When does the else part run? (a) always (b) when the test is true (c) when the test is false (d) never
-
10.🔀 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) Bronze (b) Gold (c) Silver -
11.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 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! -
13.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What number does this shop app show?
let total = 390;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 Which badge does this quiz app show?
let marks = 28;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 16.🔀 What does if / else let an app do? (a) pick one of two actions (b) repeat forever (c) save a photo (d) draw a screen
-
17.🔀 What does this PIN rule show?
let pin = "86140";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
18.🔀 What does this battery rule show?
let battery = 24;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
19.🔀 What does this sign-up rule show?
let age = 9;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
20.🔀 What number does this shop app show?
let total = 330;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 What does this battery rule show?
let battery = 63;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
22.🔀 What does this battery rule show?
let battery = 4;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
23.🔀 Which badge does this quiz app show?
let marks = 24;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
24.🔀 What does this battery rule show?
let battery = 97;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
25.🔀 Which badge does this quiz app show?
let marks = 66;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
26.🔀 What does this PIN rule show?
let pin = "508";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
27.🔀 Which badge does this quiz app show?
let marks = 85;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
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.🔀 What does this PIN rule show?
let pin = "300";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
30.🔀 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 -
31.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
33.🔀 What does this battery rule show?
let battery = 27;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
34.🔀 Which badge does this quiz app show?
let marks = 78;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
35.🔀 What does this battery rule show?
let battery = 56;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
36.🔀 What number does this shop app show?
let total = 650;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 Which badge does this quiz app show?
let marks = 32;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
38.🔀 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! -
39.🔀 Which badge does this quiz app show?
let marks = 84;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
40.🔀 What does this PIN rule show?
let pin = "522";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- Use 4 digits
- Welcome!
- Use 4 digits
- Battery OK
- Ask a parent
- ===
- only one
- Battery OK
- when the test is false
- Bronze
- 320
- Welcome!
- 380
- 390
- Bronze
- pick one of two actions
- Use 4 digits
- Battery OK
- Ask a parent
- 330
- Battery OK
- Low battery
- Bronze
- Battery OK
- Silver
- Use 4 digits
- Gold
- Battery OK
- Use 4 digits
- Welcome!
- 230
- Battery OK
- Battery OK
- Silver
- Battery OK
- 600
- Bronze
- Ask a parent
- Gold
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students