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 = 90;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
2.🔀 Which badge does this quiz app show?
let marks = 48;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
3.🔀 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! -
4.🔀 What does this PIN rule show?
let pin = "54069";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
5.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 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 -
7.🔀 What does this PIN rule show?
let pin = "7313";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
8.🔀 What does this battery rule show?
let battery = 54;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
9.🔀 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! - 10.🔀 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
-
11.🔀 What does this battery rule show?
let battery = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
12.🔀 Which badge does this quiz app show?
let marks = 72;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
13.🔀 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 -
14.🔀 What does this battery rule show?
let battery = 70;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 15.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) none (d) all of them
-
16.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What number does this shop app show?
let total = 600;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What does this battery rule show?
let battery = 90;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
19.🔀 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 -
20.🔀 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 - 21.🔀 What does >= mean? (a) greater than or equal (b) not equal (c) smaller or equal (d) less than
-
22.🔀 What does this PIN rule show?
let pin = "56266";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
23.🔀 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! -
24.🔀 Which badge does this quiz app show?
let marks = 70;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
25.🔀 Which badge does this quiz app show?
let marks = 80;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
26.🔀 What does this PIN rule show?
let pin = "77474";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
27.🔀 What does this battery rule show?
let battery = 44;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
28.🔀 What does this PIN rule show?
let pin = "96499";
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 = 380;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 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 -
31.🔀 What does this battery rule show?
let battery = 77;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
32.🔀 What does this PIN rule show?
let pin = "41882";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 33.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) => (d) ===
-
34.🔀 What does this PIN rule show?
let pin = "804";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What does this PIN rule show?
let pin = "64345";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
36.🔀 What number does this shop app show?
let total = 710;
if (total > 500) {
total = total - 50;
}
show(total); - 37.🔀 When does the else part run? (a) when the test is true (b) always (c) never (d) when the test is false
-
38.🔀 What number does this shop app show?
let total = 620;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 What number does this shop app show?
let total = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this battery rule show?
let battery = 64;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- Gold
- Bronze
- Welcome!
- Use 4 digits
- 350
- Battery OK
- PIN saved
- Battery OK
- Welcome!
- pick one of two actions
- Low battery
- Silver
- Ask a parent
- Battery OK
- only one
- 590
- 550
- Battery OK
- Battery OK
- Welcome!
- greater than or equal
- Use 4 digits
- Ask a parent
- Silver
- Gold
- Use 4 digits
- Battery OK
- Use 4 digits
- 380
- Low battery
- Battery OK
- Use 4 digits
- ===
- Use 4 digits
- Use 4 digits
- 660
- when the test is false
- 570
- 210
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students