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) Ask a parent (b) Welcome! -
2.🔀 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 -
3.🔀 What does this battery rule show?
let battery = 37;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 4.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) => (d) ===
-
5.🔀 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 -
6.🔀 Which badge does this quiz app show?
let marks = 34;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
7.🔀 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! -
8.🔀 What number does this shop app show?
let total = 700;
if (total > 500) {
total = total - 50;
}
show(total); - 9.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) repeat forever (d) draw a screen
-
10.🔀 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) Gold (c) Silver -
11.🔀 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 - 12.🔀 When does the else part run? (a) when the test is false (b) always (c) never (d) when the test is true
-
13.🔀 What does this PIN rule show?
let pin = "1090";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
14.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 What does this PIN rule show?
let pin = "6818";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
16.🔀 What does this PIN rule show?
let pin = "95743";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
17.🔀 What does this battery rule show?
let battery = 19;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
18.🔀 What number does this shop app show?
let total = 770;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 What number does this shop app show?
let total = 570;
if (total > 500) {
total = total - 50;
}
show(total); -
20.🔀 What does this sign-up rule show?
let age = 14;
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 = "44445";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
22.🔀 What does this battery rule show?
let battery = 52;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
23.🔀 What does this PIN rule show?
let pin = "995";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
24.🔀 What number does this shop app show?
let total = 220;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 What does this battery rule show?
let battery = 80;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
26.🔀 What does this battery rule show?
let battery = 31;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
27.🔀 What does this PIN rule show?
let pin = "582";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What number does this shop app show?
let total = 660;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 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) Silver (b) Bronze (c) Gold -
30.🔀 What does this PIN rule show?
let pin = "68201";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
31.🔀 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 -
32.🔀 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 -
33.🔀 Which badge does this quiz app show?
let marks = 91;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver - 34.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) less than (d) smaller or equal
-
35.🔀 What number does this shop app show?
let total = 890;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this battery rule show?
let battery = 61;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
37.🔀 What does this PIN rule show?
let pin = "25438";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
38.🔀 What does this PIN rule show?
let pin = "564";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
39.🔀 What does this battery rule show?
let battery = 43;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 40.🔀 With if / else if / else, how many parts run? (a) none (b) only one (c) two (d) all of them
Answer key
- Ask a parent
- Battery OK
- Battery OK
- ===
- Ask a parent
- Bronze
- Welcome!
- 650
- pick one of two actions
- Gold
- Welcome!
- when the test is false
- PIN saved
- 350
- PIN saved
- Use 4 digits
- Low battery
- 720
- 520
- Welcome!
- Use 4 digits
- Battery OK
- Use 4 digits
- 220
- Battery OK
- Battery OK
- Use 4 digits
- 610
- Silver
- Use 4 digits
- Ask a parent
- Ask a parent
- Gold
- greater than or equal
- 840
- Battery OK
- Use 4 digits
- Use 4 digits
- Battery OK
- only one
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students