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.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) => (c) = (d) ===
-
2.🔀 What does this PIN rule show?
let pin = "1569";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
3.🔀 What number does this shop app show?
let total = 450;
if (total > 500) {
total = total - 50;
}
show(total); - 4.🔀 With if / else if / else, how many parts run? (a) all of them (b) two (c) only one (d) none
-
5.🔀 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! - 6.🔀 What does >= mean? (a) smaller or equal (b) greater than or equal (c) less than (d) not equal
-
7.🔀 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) Bronze (b) Silver (c) Gold - 8.🔀 When does the else part run? (a) when the test is true (b) always (c) never (d) when the test is false
- 9.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) repeat forever (d) draw a screen
-
10.🔀 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 -
11.🔀 What does this PIN rule show?
let pin = "27038";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
12.🔀 Which badge does this quiz app show?
let marks = 41;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
13.🔀 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 -
14.🔀 What number does this shop app show?
let total = 580;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 What does this battery rule show?
let battery = 19;
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 = 17;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
17.🔀 What does this battery rule show?
let battery = 64;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
18.🔀 Which badge does this quiz app show?
let marks = 78;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
19.🔀 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 -
20.🔀 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) Silver (b) Bronze (c) Gold -
21.🔀 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! -
22.🔀 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) Gold (b) Bronze (c) Silver -
23.🔀 What does this battery rule show?
let battery = 26;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
24.🔀 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 -
25.🔀 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 -
26.🔀 What number does this shop app show?
let total = 610;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What number does this shop app show?
let total = 370;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 What does this battery rule show?
let battery = 73;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
29.🔀 What number does this shop app show?
let total = 830;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 What number does this shop app show?
let total = 540;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 What does this PIN rule show?
let pin = "1376";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
33.🔀 What does this PIN rule show?
let pin = "43587";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
34.🔀 What does this PIN rule show?
let pin = "54374";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What does this PIN rule show?
let pin = "250";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
36.🔀 What does this PIN rule show?
let pin = "3042";
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 = "1832";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
38.🔀 What number does this shop app show?
let total = 810;
if (total > 500) {
total = total - 50;
}
show(total); -
39.🔀 What does this PIN rule show?
let pin = "904";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
40.🔀 What does this battery rule show?
let battery = 65;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- ===
- PIN saved
- 450
- only one
- Welcome!
- greater than or equal
- Silver
- when the test is false
- pick one of two actions
- Silver
- Use 4 digits
- Bronze
- Welcome!
- 530
- Low battery
- Welcome!
- Battery OK
- Silver
- Low battery
- Gold
- Ask a parent
- Silver
- Battery OK
- Battery OK
- Ask a parent
- 560
- 370
- Battery OK
- 780
- 590
- 490
- PIN saved
- Use 4 digits
- Use 4 digits
- Use 4 digits
- PIN saved
- PIN saved
- 760
- Use 4 digits
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students