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 number does this shop app show?
let total = 730;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 What number does this shop app show?
let total = 360;
if (total > 500) {
total = total - 50;
}
show(total); - 3.🔀 When does the else part run? (a) never (b) when the test is true (c) when the test is false (d) always
-
4.🔀 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 -
5.🔀 What does this battery rule show?
let battery = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
6.🔀 What number does this shop app show?
let total = 400;
if (total > 500) {
total = total - 50;
}
show(total); - 7.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) pick one of two actions (d) draw a screen
-
8.🔀 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) Gold (b) Silver (c) Bronze -
9.🔀 What does this battery rule show?
let battery = 62;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
10.🔀 What does this battery rule show?
let battery = 17;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
11.🔀 Which badge does this quiz app show?
let marks = 58;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
12.🔀 What does this PIN rule show?
let pin = "637";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 What does this sign-up rule show?
let age = 16;
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 = 85;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
15.🔀 What does this battery rule show?
let battery = 92;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
16.🔀 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 -
17.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 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 -
19.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
20.🔀 What number does this shop app show?
let total = 250;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 Which badge does this quiz app show?
let marks = 43;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
22.🔀 Which badge does this quiz app show?
let marks = 75;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
23.🔀 What does this battery rule show?
let battery = 32;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
24.🔀 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) Silver (c) Bronze -
25.🔀 What does this battery rule show?
let battery = 55;
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 = 280;
if (total > 500) {
total = total - 50;
}
show(total); - 27.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
- 28.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) greater than or equal (d) less than
-
29.🔀 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! -
30.🔀 What does this PIN rule show?
let pin = "72575";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 What number does this shop app show?
let total = 620;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 Which badge does this quiz app show?
let marks = 29;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
33.🔀 What does this PIN rule show?
let pin = "2183";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
34.🔀 What does this PIN rule show?
let pin = "65832";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What does this battery rule show?
let battery = 9;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 36.🔀 With if / else if / else, how many parts run? (a) none (b) all of them (c) only one (d) two
-
37.🔀 What number does this shop app show?
let total = 770;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this battery rule show?
let battery = 45;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
39.🔀 What number does this shop app show?
let total = 800;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this PIN rule show?
let pin = "4439";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved
Answer key
- 680
- 360
- when the test is false
- Welcome!
- Low battery
- 400
- pick one of two actions
- Bronze
- Battery OK
- Low battery
- Silver
- Use 4 digits
- Welcome!
- Battery OK
- Battery OK
- Ask a parent
- 380
- Ask a parent
- 780
- 250
- Bronze
- Silver
- Battery OK
- Bronze
- Battery OK
- 280
- ===
- greater than or equal
- Welcome!
- Use 4 digits
- 570
- Bronze
- PIN saved
- Use 4 digits
- Low battery
- only one
- 720
- Battery OK
- 750
- PIN saved
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students