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 = "168";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
2.🔀 Which badge does this quiz app show?
let marks = 45;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
3.🔀 What does this battery rule show?
let battery = 43;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 4.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) === (c) => (d) =
-
5.🔀 What does this battery rule show?
let battery = 74;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
6.🔀 What does this battery rule show?
let battery = 60;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
7.🔀 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! -
8.🔀 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) Silver (c) Bronze -
9.🔀 What does this battery rule show?
let battery = 77;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
10.🔀 Which badge does this quiz app show?
let marks = 38;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
11.🔀 What number does this shop app show?
let total = 220;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 What does this PIN rule show?
let pin = "258";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 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 -
14.🔀 What does this PIN rule show?
let pin = "4642";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
15.🔀 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 - 16.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) repeat forever (d) pick one of two actions
-
17.🔀 What does this battery rule show?
let battery = 88;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
18.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
19.🔀 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) Bronze (b) Gold (c) Silver -
20.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 What does this PIN rule show?
let pin = "812";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
22.🔀 What number does this shop app show?
let total = 480;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 What does this sign-up rule show?
let age = 14;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
24.🔀 What does this PIN rule show?
let pin = "497";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 25.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) none (d) only one
-
26.🔀 Which badge does this quiz app show?
let marks = 99;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
27.🔀 What does this PIN rule show?
let pin = "106";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
28.🔀 What does this PIN rule show?
let pin = "403";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
29.🔀 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 -
30.🔀 What number does this shop app show?
let total = 210;
if (total > 500) {
total = total - 50;
}
show(total); - 31.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
-
32.🔀 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) Silver (c) Bronze -
33.🔀 What does this battery rule show?
let battery = 23;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 34.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) not equal (d) less than
-
35.🔀 What does this PIN rule show?
let pin = "6230";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
36.🔀 What does this PIN rule show?
let pin = "79844";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
37.🔀 What does this PIN rule show?
let pin = "5719";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
38.🔀 What number does this shop app show?
let total = 240;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 What does this battery rule show?
let battery = 78;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
40.🔀 Which badge does this quiz app show?
let marks = 47;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold
Answer key
- Use 4 digits
- Bronze
- Battery OK
- ===
- Battery OK
- Battery OK
- Ask a parent
- Bronze
- Battery OK
- Bronze
- 220
- Use 4 digits
- Ask a parent
- PIN saved
- Battery OK
- pick one of two actions
- Battery OK
- Ask a parent
- Bronze
- 320
- Use 4 digits
- 480
- Welcome!
- Use 4 digits
- only one
- Gold
- Use 4 digits
- Use 4 digits
- Welcome!
- 210
- when the test is false
- Bronze
- Battery OK
- greater than or equal
- PIN saved
- Use 4 digits
- PIN saved
- 240
- Battery OK
- Bronze
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students