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 = 290;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 What does this battery rule show?
let battery = 68;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
3.🔀 What does this sign-up rule show?
let age = 14;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
4.🔀 Which badge does this quiz app show?
let marks = 49;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
5.🔀 What does this PIN rule show?
let pin = "342";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
6.🔀 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 -
7.🔀 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! - 8.🔀 What does if / else let an app do? (a) pick one of two actions (b) draw a screen (c) save a photo (d) repeat forever
-
9.🔀 What does this battery rule show?
let battery = 97;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
10.🔀 What number does this shop app show?
let total = 900;
if (total > 500) {
total = total - 50;
}
show(total); -
11.🔀 Which badge does this quiz app show?
let marks = 20;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
12.🔀 What does this PIN rule show?
let pin = "1717";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 13.🔀 What does >= mean? (a) not equal (b) greater than or equal (c) smaller or equal (d) less than
-
14.🔀 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) Silver (c) Gold -
15.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); - 16.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) !== (c) => (d) =
- 17.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) none (d) only one
- 18.🔀 When does the else part run? (a) when the test is false (b) never (c) when the test is true (d) always
-
19.🔀 What does this sign-up rule show?
let age = 16;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
20.🔀 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 -
21.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What does this PIN rule show?
let pin = "831";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
23.🔀 What does this battery rule show?
let battery = 1;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
24.🔀 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! -
25.🔀 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 -
26.🔀 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! -
27.🔀 Which badge does this quiz app show?
let marks = 71;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
28.🔀 Which badge does this quiz app show?
let marks = 50;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
29.🔀 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) Bronze (b) Gold (c) Silver -
30.🔀 What does this battery rule show?
let battery = 57;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
31.🔀 Which badge does this quiz app show?
let marks = 97;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
32.🔀 What number does this shop app show?
let total = 630;
if (total > 500) {
total = total - 50;
}
show(total); -
33.🔀 What does this PIN rule show?
let pin = "339";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
34.🔀 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 -
35.🔀 What does this sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
36.🔀 What does this battery rule show?
let battery = 73;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
37.🔀 What number does this shop app show?
let total = 320;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this PIN rule show?
let pin = "57339";
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 = 65;
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 = 81;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver
Answer key
- 290
- Battery OK
- Welcome!
- Bronze
- Use 4 digits
- Ask a parent
- Welcome!
- pick one of two actions
- Battery OK
- 850
- Bronze
- PIN saved
- greater than or equal
- Gold
- 700
- ===
- only one
- when the test is false
- Welcome!
- Battery OK
- 510
- Use 4 digits
- Low battery
- Welcome!
- Battery OK
- Ask a parent
- Silver
- Silver
- Silver
- Battery OK
- Gold
- 580
- Use 4 digits
- Ask a parent
- Ask a parent
- Battery OK
- 320
- Use 4 digits
- Battery OK
- Gold
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students