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 = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
2.🔀 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 -
3.🔀 What number does this shop app show?
let total = 680;
if (total > 500) {
total = total - 50;
}
show(total); -
4.🔀 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) Silver (c) Gold -
5.🔀 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! -
6.🔀 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 -
7.🔀 What number does this shop app show?
let total = 770;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 What number does this shop app show?
let total = 550;
if (total > 500) {
total = total - 50;
}
show(total); - 9.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) draw a screen (d) pick one of two actions
-
10.🔀 Which badge does this quiz app show?
let marks = 56;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
11.🔀 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 -
12.🔀 What number does this shop app show?
let total = 300;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 What number does this shop app show?
let total = 250;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What number does this shop app show?
let total = 500;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 What number does this shop app show?
let total = 580;
if (total > 500) {
total = total - 50;
}
show(total); -
16.🔀 What does this PIN rule show?
let pin = "876";
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 = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
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.🔀 Which badge does this quiz app show?
let marks = 52;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
20.🔀 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 -
21.🔀 Which badge does this quiz app show?
let marks = 21;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze - 22.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) !== (c) => (d) ===
-
23.🔀 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 -
24.🔀 Which badge does this quiz app show?
let marks = 33;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
25.🔀 What number does this shop app show?
let total = 720;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What number does this shop app show?
let total = 870;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 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! -
28.🔀 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) Gold (b) Bronze (c) Silver -
29.🔀 What does this battery rule show?
let battery = 99;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
30.🔀 What does this battery rule show?
let battery = 96;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
31.🔀 What number does this shop app show?
let total = 840;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 Which badge does this quiz app show?
let marks = 67;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
33.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this PIN rule show?
let pin = "987";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 What does this PIN rule show?
let pin = "3752";
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 = "522";
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 = 93;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
39.🔀 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 -
40.🔀 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!
Answer key
- Ask a parent
- Battery OK
- 630
- Gold
- Welcome!
- Ask a parent
- 720
- 500
- pick one of two actions
- Silver
- Ask a parent
- 300
- 250
- 500
- 530
- Use 4 digits
- Low battery
- Welcome!
- Silver
- Silver
- Bronze
- ===
- Low battery
- Bronze
- 670
- 820
- Ask a parent
- Gold
- Battery OK
- Battery OK
- 790
- Silver
- 700
- Use 4 digits
- 320
- PIN saved
- Use 4 digits
- Battery OK
- Battery OK
- Ask a parent
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students