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.🔀 Which badge does this quiz app show?
let marks = 62;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
2.🔀 What does this PIN rule show?
let pin = "17554";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
3.🔀 What does this PIN rule show?
let pin = "60144";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
4.🔀 What does this battery rule show?
let battery = 51;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 5.🔀 When does the else part run? (a) when the test is false (b) when the test is true (c) never (d) always
-
6.🔀 What does this sign-up rule show?
let age = 17;
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 = 420;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 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! - 9.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
- 10.🔀 What does >= mean? (a) less than (b) smaller or equal (c) greater than or equal (d) not equal
-
11.🔀 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 -
12.🔀 What does this PIN rule show?
let pin = "96703";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 What number does this shop app show?
let total = 520;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What does this PIN rule show?
let pin = "2596";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
15.🔀 What does this PIN rule show?
let pin = "1955";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
16.🔀 What number does this shop app show?
let total = 330;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What number does this shop app show?
let total = 820;
if (total > 500) {
total = total - 50;
}
show(total); -
19.🔀 What does this battery rule show?
let battery = 70;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
20.🔀 Which badge does this quiz app show?
let marks = 86;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 21.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) only one (d) all of them
-
22.🔀 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! -
23.🔀 What does this battery rule show?
let battery = 62;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
24.🔀 What number does this shop app show?
let total = 540;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 What does this PIN rule show?
let pin = "39381";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
26.🔀 Which badge does this quiz app show?
let marks = 48;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
27.🔀 What does this battery rule show?
let battery = 86;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
28.🔀 Which badge does this quiz app show?
let marks = 98;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
29.🔀 What does this sign-up rule show?
let age = 12;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
30.🔀 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! -
31.🔀 What does this battery rule show?
let battery = 63;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
32.🔀 Which badge does this quiz app show?
let marks = 70;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
33.🔀 What number does this shop app show?
let total = 450;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this sign-up rule show?
let age = 11;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
35.🔀 Which badge does this quiz app show?
let marks = 80;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
36.🔀 Which badge does this quiz app show?
let marks = 94;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
37.🔀 Which badge does this quiz app show?
let marks = 85;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze - 38.🔀 What does if / else let an app do? (a) repeat forever (b) pick one of two actions (c) draw a screen (d) save a photo
-
39.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this battery rule show?
let battery = 4;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK
Answer key
- Silver
- Use 4 digits
- Use 4 digits
- Battery OK
- when the test is false
- Welcome!
- 420
- Welcome!
- ===
- greater than or equal
- Ask a parent
- Use 4 digits
- 470
- PIN saved
- PIN saved
- 330
- 590
- 770
- Battery OK
- Gold
- only one
- Welcome!
- Battery OK
- 490
- Use 4 digits
- Bronze
- Battery OK
- Gold
- Ask a parent
- Welcome!
- Battery OK
- Silver
- 450
- Ask a parent
- Gold
- Gold
- Gold
- pick one of two actions
- 310
- Low battery
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students