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 >= mean? (a) not equal (b) smaller or equal (c) less than (d) greater than or equal
- 2.🔀 When does the else part run? (a) never (b) always (c) when the test is true (d) when the test is false
-
3.🔀 What does this battery rule show?
let battery = 11;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 4.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
- 5.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) all of them (d) none
-
6.🔀 Which badge does this quiz app show?
let marks = 22;
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 = 570;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 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 -
9.🔀 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) Bronze (b) Gold (c) Silver -
10.🔀 What does this PIN rule show?
let pin = "1226";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
11.🔀 What does this battery rule show?
let battery = 22;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 12.🔀 What does if / else let an app do? (a) repeat forever (b) save a photo (c) pick one of two actions (d) draw a screen
-
13.🔀 What does this battery rule show?
let battery = 4;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
14.🔀 What does this battery rule show?
let battery = 19;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
15.🔀 What does this battery rule show?
let battery = 93;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
16.🔀 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 -
17.🔀 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! -
18.🔀 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 -
19.🔀 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) Bronze (b) Silver (c) Gold -
20.🔀 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 -
21.🔀 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! -
22.🔀 What does this battery rule show?
let battery = 83;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
23.🔀 What does this PIN rule show?
let pin = "719";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
24.🔀 What does this PIN rule show?
let pin = "709";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
25.🔀 What does this PIN rule show?
let pin = "7183";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
26.🔀 What does this sign-up rule show?
let age = 8;
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 = "87454";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 Which badge does this quiz app show?
let marks = 67;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
30.🔀 What does this battery rule show?
let battery = 49;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
31.🔀 What does this PIN rule show?
let pin = "87656";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
32.🔀 What does this battery rule show?
let battery = 80;
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 = 62;
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 = "918";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 Which badge does this quiz app show?
let marks = 94;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
36.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 Which badge does this quiz app show?
let marks = 86;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
38.🔀 Which badge does this quiz app show?
let marks = 100;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
39.🔀 What number does this shop app show?
let total = 780;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What number does this shop app show?
let total = 400;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- greater than or equal
- when the test is false
- Low battery
- ===
- only one
- Bronze
- 520
- Welcome!
- Bronze
- PIN saved
- Battery OK
- pick one of two actions
- Low battery
- Low battery
- Battery OK
- Ask a parent
- Ask a parent
- Welcome!
- Silver
- Bronze
- Ask a parent
- Battery OK
- Use 4 digits
- Use 4 digits
- PIN saved
- Ask a parent
- Use 4 digits
- 260
- Silver
- Battery OK
- Use 4 digits
- Battery OK
- Battery OK
- Use 4 digits
- Gold
- 590
- Gold
- Gold
- 730
- 400
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students