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 = 8;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
2.🔀 What does this PIN rule show?
let pin = "25201";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 3.🔀 What does if / else let an app do? (a) pick one of two actions (b) repeat forever (c) draw a screen (d) save a photo
-
4.🔀 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) Silver (b) Bronze (c) Gold -
5.🔀 What number does this shop app show?
let total = 630;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What does this battery rule show?
let battery = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
7.🔀 What number does this shop app show?
let total = 760;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 What number does this shop app show?
let total = 820;
if (total > 500) {
total = total - 50;
}
show(total); - 9.🔀 What does >= mean? (a) less than (b) smaller or equal (c) not equal (d) greater than or equal
-
10.🔀 What does this sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
11.🔀 What number does this shop app show?
let total = 800;
if (total > 500) {
total = total - 50;
}
show(total); -
12.🔀 What number does this shop app show?
let total = 810;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 What does this PIN rule show?
let pin = "7796";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
14.🔀 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 -
15.🔀 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 -
16.🔀 Which badge does this quiz app show?
let marks = 68;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze - 17.🔀 When does the else part run? (a) always (b) when the test is true (c) never (d) when the test is false
-
18.🔀 What does this battery rule show?
let battery = 85;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
19.🔀 What does this sign-up rule show?
let age = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
20.🔀 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! -
21.🔀 What does this PIN rule show?
let pin = "8133";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
22.🔀 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 - 23.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) two (d) only one
-
24.🔀 Which badge does this quiz app show?
let marks = 55;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
25.🔀 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 -
26.🔀 What number does this shop app show?
let total = 650;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What number does this shop app show?
let total = 680;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What does this battery rule show?
let battery = 89;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
29.🔀 What number does this shop app show?
let total = 690;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What does this battery rule show?
let battery = 35;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
31.🔀 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 -
32.🔀 What number does this shop app show?
let total = 420;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 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) Silver (b) Bronze (c) Gold -
34.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 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 -
36.🔀 What does this battery rule show?
let battery = 64;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
37.🔀 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 -
38.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 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 -
40.🔀 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
Answer key
- Ask a parent
- Use 4 digits
- pick one of two actions
- Bronze
- 580
- Low battery
- 710
- 770
- greater than or equal
- Ask a parent
- 750
- 760
- PIN saved
- Battery OK
- Ask a parent
- Silver
- when the test is false
- Battery OK
- Ask a parent
- Welcome!
- PIN saved
- Bronze
- only one
- Silver
- Low battery
- 600
- 630
- Battery OK
- 640
- Battery OK
- Welcome!
- 420
- Bronze
- 340
- Silver
- Battery OK
- Battery OK
- 320
- Low battery
- Ask a parent
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students