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 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! -
2.🔀 What does this PIN rule show?
let pin = "736";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
3.🔀 Which badge does this quiz app show?
let marks = 84;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
4.🔀 What does this PIN rule show?
let pin = "7462";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
5.🔀 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! - 6.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) all of them (d) only one
-
7.🔀 What does this battery rule show?
let battery = 55;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery - 8.🔀 In this course’s code, which sign tests “is equal to”? (a) !== (b) = (c) === (d) =>
-
9.🔀 Which badge does this quiz app show?
let marks = 46;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
10.🔀 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) Bronze (b) Gold (c) Silver -
11.🔀 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) Gold (b) Silver (c) Bronze - 12.🔀 What does if / else let an app do? (a) repeat forever (b) draw a screen (c) pick one of two actions (d) save a photo
-
13.🔀 What does this battery rule show?
let battery = 24;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
14.🔀 What number does this shop app show?
let total = 890;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 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 -
16.🔀 What does this battery rule show?
let battery = 43;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
17.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What does this battery rule show?
let battery = 25;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
19.🔀 Which badge does this quiz app show?
let marks = 87;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
20.🔀 What number does this shop app show?
let total = 820;
if (total > 500) {
total = total - 50;
}
show(total); - 21.🔀 When does the else part run? (a) always (b) never (c) when the test is true (d) when the test is false
- 22.🔀 What does >= mean? (a) greater than or equal (b) less than (c) smaller or equal (d) not equal
-
23.🔀 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 -
24.🔀 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) Gold (b) Bronze (c) Silver -
25.🔀 Which badge does this quiz app show?
let marks = 21;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
26.🔀 What does this battery rule show?
let battery = 49;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
27.🔀 Which badge does this quiz app show?
let marks = 26;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
28.🔀 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! -
29.🔀 What does this PIN rule show?
let pin = "2417";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
30.🔀 Which badge does this quiz app show?
let marks = 66;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
31.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 Which badge does this quiz app show?
let marks = 65;
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 = "155";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
34.🔀 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) Bronze (b) Gold (c) Silver -
35.🔀 What does this battery rule show?
let battery = 94;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
36.🔀 What does this battery rule show?
let battery = 20;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
37.🔀 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! -
38.🔀 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) Bronze (b) Silver (c) Gold -
39.🔀 What does this battery rule show?
let battery = 99;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
40.🔀 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
Answer key
- Ask a parent
- Use 4 digits
- Gold
- PIN saved
- Ask a parent
- only one
- Battery OK
- ===
- Bronze
- Bronze
- Gold
- pick one of two actions
- Battery OK
- 840
- Ask a parent
- Battery OK
- 230
- Battery OK
- Gold
- 770
- when the test is false
- greater than or equal
- Ask a parent
- Silver
- Bronze
- Battery OK
- Bronze
- Welcome!
- PIN saved
- Silver
- 800
- Silver
- Use 4 digits
- Silver
- Battery OK
- Battery OK
- Welcome!
- Silver
- Battery OK
- Welcome!
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students