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.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) all of them (d) only one
-
2.🔀 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 -
3.🔀 Which badge does this quiz app show?
let marks = 42;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
4.🔀 What does this PIN rule show?
let pin = "361";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
5.🔀 What does this battery rule show?
let battery = 30;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
6.🔀 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) Gold (c) Bronze -
7.🔀 What number does this shop app show?
let total = 480;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 What does this PIN rule show?
let pin = "10077";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
9.🔀 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 -
10.🔀 What does this PIN rule show?
let pin = "153";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
11.🔀 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! -
12.🔀 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 -
13.🔀 Which badge does this quiz app show?
let marks = 95;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
14.🔀 What does this PIN rule show?
let pin = "25307";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 15.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) => (c) !== (d) ===
-
16.🔀 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) Gold (b) Bronze (c) Silver -
17.🔀 Which badge does this quiz app show?
let marks = 71;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
18.🔀 What number does this shop app show?
let total = 550;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 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! - 20.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) repeat forever (d) draw a screen
- 21.🔀 What does >= mean? (a) greater than or equal (b) smaller or equal (c) not equal (d) less than
-
22.🔀 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) Bronze (c) Silver -
23.🔀 What number does this shop app show?
let total = 660;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 What does this battery rule show?
let battery = 58;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
25.🔀 What does this PIN rule show?
let pin = "67322";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
26.🔀 Which badge does this quiz app show?
let marks = 92;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
27.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What does this PIN rule show?
let pin = "49144";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
29.🔀 What number does this shop app show?
let total = 670;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What does this sign-up rule show?
let age = 17;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
31.🔀 What does this PIN rule show?
let pin = "31799";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
32.🔀 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 -
33.🔀 What does this sign-up rule show?
let age = 15;
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 = "38229";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What does this PIN rule show?
let pin = "289";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 36.🔀 When does the else part run? (a) always (b) when the test is true (c) when the test is false (d) never
-
37.🔀 What does this PIN rule show?
let pin = "273";
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 = 590;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 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!
Answer key
- only one
- Welcome!
- Bronze
- Use 4 digits
- Battery OK
- Bronze
- 480
- Use 4 digits
- Battery OK
- Use 4 digits
- Ask a parent
- Low battery
- Gold
- Use 4 digits
- ===
- Gold
- Silver
- 500
- Ask a parent
- pick one of two actions
- greater than or equal
- Silver
- 610
- Battery OK
- Use 4 digits
- Gold
- 320
- Use 4 digits
- 620
- Welcome!
- Use 4 digits
- Low battery
- Welcome!
- Use 4 digits
- Use 4 digits
- when the test is false
- Use 4 digits
- 540
- 340
- Welcome!
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students