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 this sign-up rule show?
let age = 9;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
2.🔀 What number does this shop app show?
let total = 540;
if (total > 500) {
total = total - 50;
}
show(total); -
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 number does this shop app show?
let total = 670;
if (total > 500) {
total = total - 50;
}
show(total); -
5.🔀 What does this PIN rule show?
let pin = "479";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
6.🔀 What number does this shop app show?
let total = 650;
if (total > 500) {
total = total - 50;
}
show(total); - 7.🔀 When does the else part run? (a) when the test is false (b) always (c) when the test is true (d) never
-
8.🔀 What does this PIN rule show?
let pin = "343";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 9.🔀 What does >= mean? (a) smaller or equal (b) less than (c) greater than or equal (d) not equal
-
10.🔀 What number does this shop app show?
let total = 510;
if (total > 500) {
total = total - 50;
}
show(total); - 11.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) = (c) === (d) !==
-
12.🔀 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 -
13.🔀 What does this battery rule show?
let battery = 77;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
14.🔀 Which badge does this quiz app show?
let marks = 51;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
15.🔀 What does this battery rule show?
let battery = 27;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
16.🔀 What does this PIN rule show?
let pin = "9698";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
17.🔀 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) Silver (c) Gold -
18.🔀 What does this PIN rule show?
let pin = "99322";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
19.🔀 What does this PIN rule show?
let pin = "1242";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
20.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
21.🔀 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 -
22.🔀 What does this PIN rule show?
let pin = "4181";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 23.🔀 With if / else if / else, how many parts run? (a) two (b) all of them (c) only one (d) none
-
24.🔀 What does this PIN rule show?
let pin = "71105";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
25.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What number does this shop app show?
let total = 790;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 Which badge does this quiz app show?
let marks = 82;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
28.🔀 What does this PIN rule show?
let pin = "8502";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
29.🔀 What does this battery rule show?
let battery = 8;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
30.🔀 What does this PIN rule show?
let pin = "162";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 31.🔀 What does if / else let an app do? (a) save a photo (b) pick one of two actions (c) draw a screen (d) repeat forever
-
32.🔀 What does this battery rule show?
let battery = 69;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
33.🔀 Which badge does this quiz app show?
let marks = 32;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
34.🔀 What does this PIN rule show?
let pin = "41306";
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 = 70;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
36.🔀 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 -
37.🔀 What does this PIN rule show?
let pin = "62407";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
38.🔀 What does this battery rule show?
let battery = 4;
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 = 59;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
40.🔀 Which badge does this quiz app show?
let marks = 26;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze
Answer key
- Ask a parent
- 490
- Welcome!
- 620
- Use 4 digits
- 600
- when the test is false
- Use 4 digits
- greater than or equal
- 460
- ===
- Low battery
- Battery OK
- Silver
- Battery OK
- PIN saved
- Bronze
- Use 4 digits
- PIN saved
- Ask a parent
- Battery OK
- PIN saved
- only one
- Use 4 digits
- 800
- 740
- Gold
- PIN saved
- Low battery
- Use 4 digits
- pick one of two actions
- Battery OK
- Bronze
- Use 4 digits
- Silver
- Welcome!
- Use 4 digits
- Low battery
- Battery OK
- Bronze
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students