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.🔀 Which badge does this quiz app show?
let marks = 41;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
2.🔀 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) Silver (b) Gold (c) Bronze -
3.🔀 What does this PIN rule show?
let pin = "466";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 4.🔀 When does the else part run? (a) always (b) never (c) when the test is false (d) when the test is true
- 5.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
-
6.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
7.🔀 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 - 8.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) all of them (d) none
-
9.🔀 What does this battery rule show?
let battery = 91;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 10.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) !== (d) =>
-
11.🔀 What does this battery rule show?
let battery = 1;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
12.🔀 What does this battery rule show?
let battery = 16;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
13.🔀 What number does this shop app show?
let total = 690;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What does this sign-up rule show?
let age = 16;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
15.🔀 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) Gold (b) Silver (c) Bronze -
16.🔀 What does this battery rule show?
let battery = 18;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
17.🔀 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 -
18.🔀 What does this battery rule show?
let battery = 29;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
19.🔀 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) Bronze (b) Gold (c) Silver -
20.🔀 What number does this shop app show?
let total = 360;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 What number does this shop app show?
let total = 670;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What number does this shop app show?
let total = 500;
if (total > 500) {
total = total - 50;
}
show(total); -
23.🔀 What number does this shop app show?
let total = 440;
if (total > 500) {
total = total - 50;
}
show(total); - 24.🔀 What does >= mean? (a) not equal (b) smaller or equal (c) greater than or equal (d) less than
-
25.🔀 What number does this shop app show?
let total = 900;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What does this sign-up rule show?
let age = 17;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
27.🔀 Which badge does this quiz app show?
let marks = 30;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
28.🔀 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) Silver (b) Bronze (c) Gold -
29.🔀 What number does this shop app show?
let total = 280;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 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 -
31.🔀 What number does this shop app show?
let total = 420;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 Which badge does this quiz app show?
let marks = 39;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
33.🔀 What number does this shop app show?
let total = 820;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this PIN rule show?
let pin = "7091";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 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 -
36.🔀 What number does this shop app show?
let total = 300;
if (total > 500) {
total = total - 50;
}
show(total); -
37.🔀 What does this battery rule show?
let battery = 52;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
38.🔀 What does this battery rule show?
let battery = 33;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
39.🔀 What does this battery rule show?
let battery = 98;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
40.🔀 What does this PIN rule show?
let pin = "48487";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved
Answer key
- Bronze
- Gold
- Use 4 digits
- when the test is false
- pick one of two actions
- 780
- Bronze
- only one
- Battery OK
- ===
- Low battery
- Low battery
- 640
- Welcome!
- Silver
- Low battery
- Ask a parent
- Battery OK
- Bronze
- 360
- 620
- 500
- 440
- greater than or equal
- 850
- Welcome!
- Bronze
- Gold
- 280
- Battery OK
- 420
- Bronze
- 770
- PIN saved
- Welcome!
- 300
- Battery OK
- Battery OK
- Battery OK
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students