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 = 210;
if (total > 500) {
total = total - 50;
}
show(total); -
2.🔀 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) Gold (c) Silver -
3.🔀 Which badge does this quiz app show?
let marks = 69;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 4.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) less than (d) not equal
-
5.🔀 Which badge does this quiz app show?
let marks = 77;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
6.🔀 What does this battery rule show?
let battery = 96;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
7.🔀 What number does this shop app show?
let total = 780;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 Which badge does this quiz app show?
let marks = 83;
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 = 2;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
10.🔀 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 -
11.🔀 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! - 12.🔀 What does if / else let an app do? (a) pick one of two actions (b) repeat forever (c) save a photo (d) draw a screen
-
13.🔀 What does this battery rule show?
let battery = 8;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
14.🔀 What does this battery rule show?
let battery = 28;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 15.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) = (c) !== (d) =>
-
16.🔀 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! -
17.🔀 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 -
18.🔀 What does this battery rule show?
let battery = 79;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
19.🔀 What does this PIN rule show?
let pin = "75618";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
20.🔀 What number does this shop app show?
let total = 670;
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) Silver (b) Gold (c) Bronze -
22.🔀 What does this PIN rule show?
let pin = "75887";
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 = 7;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
24.🔀 What does this battery rule show?
let battery = 23;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
25.🔀 What does this battery rule show?
let battery = 9;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
26.🔀 Which badge does this quiz app show?
let marks = 24;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 27.🔀 When does the else part run? (a) never (b) when the test is true (c) when the test is false (d) always
-
28.🔀 What does this battery rule show?
let battery = 75;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
29.🔀 What does this PIN rule show?
let pin = "867";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
30.🔀 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 -
31.🔀 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 -
32.🔀 What does this battery rule show?
let battery = 37;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 33.🔀 With if / else if / else, how many parts run? (a) all of them (b) only one (c) none (d) two
-
34.🔀 What does this PIN rule show?
let pin = "91073";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What number does this shop app show?
let total = 660;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 Which badge does this quiz app show?
let marks = 63;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
37.🔀 What number does this shop app show?
let total = 540;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this PIN rule show?
let pin = "1144";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 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 -
40.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- 210
- Gold
- Silver
- greater than or equal
- Silver
- Battery OK
- 730
- Gold
- Low battery
- Welcome!
- Ask a parent
- pick one of two actions
- Low battery
- Battery OK
- ===
- Ask a parent
- Ask a parent
- Battery OK
- Use 4 digits
- 620
- Bronze
- Use 4 digits
- Low battery
- Battery OK
- Low battery
- Bronze
- when the test is false
- Battery OK
- Use 4 digits
- Ask a parent
- Welcome!
- Battery OK
- only one
- Use 4 digits
- 610
- Silver
- 490
- PIN saved
- Welcome!
- 260
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students