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 = 74;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
2.🔀 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 -
3.🔀 What number does this shop app show?
let total = 670;
if (total > 500) {
total = total - 50;
}
show(total); - 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 = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What does this battery rule show?
let battery = 46;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 7.🔀 What does >= mean? (a) smaller or equal (b) less than (c) not equal (d) greater than or equal
-
8.🔀 What does this battery rule show?
let battery = 42;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
9.🔀 What does this battery rule show?
let battery = 13;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
10.🔀 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! -
11.🔀 What does this PIN rule show?
let pin = "6551";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
12.🔀 What does this battery rule show?
let battery = 58;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
13.🔀 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 -
14.🔀 What does this PIN rule show?
let pin = "675";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
15.🔀 What does this battery rule show?
let battery = 10;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 16.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
-
17.🔀 What does this battery rule show?
let battery = 47;
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 = 17;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
19.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
20.🔀 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! -
21.🔀 Which badge does this quiz app show?
let marks = 28;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
22.🔀 What does this PIN rule show?
let pin = "28322";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
23.🔀 What number does this shop app show?
let total = 270;
if (total > 500) {
total = total - 50;
}
show(total); -
24.🔀 What number does this shop app show?
let total = 520;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 What number does this shop app show?
let total = 870;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 Which badge does this quiz app show?
let marks = 57;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
27.🔀 What does this PIN rule show?
let pin = "4722";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What does this PIN rule show?
let pin = "792";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
29.🔀 What does this battery rule show?
let battery = 39;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 30.🔀 With if / else if / else, how many parts run? (a) only one (b) two (c) all of them (d) none
-
31.🔀 Which badge does this quiz app show?
let marks = 87;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
32.🔀 What does this sign-up rule show?
let age = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
33.🔀 Which badge does this quiz app show?
let marks = 63;
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 = 410;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 Which badge does this quiz app show?
let marks = 44;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
36.🔀 What does this PIN rule show?
let pin = "9243";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
37.🔀 What does this PIN rule show?
let pin = "694";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
38.🔀 What does this battery rule show?
let battery = 7;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
39.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK
Answer key
- Silver
- Gold
- 620
- ===
- 210
- Battery OK
- greater than or equal
- Battery OK
- Low battery
- Ask a parent
- PIN saved
- Battery OK
- Battery OK
- Use 4 digits
- Low battery
- when the test is false
- Battery OK
- Welcome!
- 590
- Welcome!
- Bronze
- Use 4 digits
- 270
- 470
- 820
- Silver
- PIN saved
- Use 4 digits
- Battery OK
- only one
- Gold
- Ask a parent
- Silver
- 410
- Bronze
- PIN saved
- Use 4 digits
- Low battery
- 260
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students