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.🔀 When does the else part run? (a) when the test is false (b) when the test is true (c) never (d) always
- 2.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) smaller or equal (d) less than
-
3.🔀 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! - 4.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) === (d) =>
-
5.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What does this PIN rule show?
let pin = "3659";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
7.🔀 What does this PIN rule show?
let pin = "70425";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
8.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
9.🔀 What number does this shop app show?
let total = 860;
if (total > 500) {
total = total - 50;
}
show(total); - 10.🔀 What does if / else let an app do? (a) draw a screen (b) repeat forever (c) pick one of two actions (d) save a photo
-
11.🔀 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! -
12.🔀 What number does this shop app show?
let total = 370;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 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! -
14.🔀 What does this PIN rule show?
let pin = "1258";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
15.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
16.🔀 What number does this shop app show?
let total = 290;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 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 -
18.🔀 Which badge does this quiz app show?
let marks = 75;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
19.🔀 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 - 20.🔀 With if / else if / else, how many parts run? (a) only one (b) none (c) all of them (d) two
-
21.🔀 What does this battery rule show?
let battery = 96;
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 = 84;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
23.🔀 What number does this shop app show?
let total = 650;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 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) Gold (b) Bronze (c) Silver -
25.🔀 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 -
26.🔀 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 -
27.🔀 Which badge does this quiz app show?
let marks = 65;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
28.🔀 What number does this shop app show?
let total = 770;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 What number does this shop app show?
let total = 390;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What does this PIN rule show?
let pin = "143";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 What does this battery rule show?
let battery = 15;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
32.🔀 Which badge does this quiz app show?
let marks = 54;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
33.🔀 Which badge does this quiz app show?
let marks = 40;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
34.🔀 What number does this shop app show?
let total = 710;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 What does this battery rule show?
let battery = 68;
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 = 400;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 What does this battery rule show?
let battery = 95;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
38.🔀 What does this PIN rule show?
let pin = "77482";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
39.🔀 What does this PIN rule show?
let pin = "3338";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
40.🔀 What does this PIN rule show?
let pin = "8509";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits
Answer key
- when the test is false
- greater than or equal
- Ask a parent
- ===
- 380
- PIN saved
- Use 4 digits
- 230
- 810
- pick one of two actions
- Welcome!
- 370
- Welcome!
- PIN saved
- 310
- 290
- Low battery
- Silver
- Battery OK
- only one
- Battery OK
- Battery OK
- 600
- Bronze
- Ask a parent
- Ask a parent
- Silver
- 720
- 390
- Use 4 digits
- Low battery
- Silver
- Bronze
- 660
- Battery OK
- 400
- Battery OK
- Use 4 digits
- PIN saved
- PIN saved
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students