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.🔀 With if / else if / else, how many parts run? (a) two (b) none (c) only one (d) all of them
-
2.🔀 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) Bronze (b) Gold (c) Silver - 3.🔀 What does if / else let an app do? (a) save a photo (b) repeat forever (c) pick one of two actions (d) draw a screen
-
4.🔀 What number does this shop app show?
let total = 270;
if (total > 500) {
total = total - 50;
}
show(total); -
5.🔀 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! -
6.🔀 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! - 7.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) !== (c) => (d) =
-
8.🔀 What does this PIN rule show?
let pin = "2807";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
9.🔀 What number does this shop app show?
let total = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
10.🔀 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 -
11.🔀 What number does this shop app show?
let total = 630;
if (total > 500) {
total = total - 50;
}
show(total); - 12.🔀 When does the else part run? (a) always (b) when the test is true (c) when the test is false (d) never
-
13.🔀 What does this PIN rule show?
let pin = "41474";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
14.🔀 What number does this shop app show?
let total = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 Which badge does this quiz app show?
let marks = 31;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
16.🔀 What number does this shop app show?
let total = 530;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 Which badge does this quiz app show?
let marks = 79;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
18.🔀 What does this PIN rule show?
let pin = "187";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
19.🔀 What does this battery rule show?
let battery = 39;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
20.🔀 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 -
21.🔀 What number does this shop app show?
let total = 760;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 What does this PIN rule show?
let pin = "47031";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
23.🔀 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 -
24.🔀 What does this battery rule show?
let battery = 51;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK - 25.🔀 What does >= mean? (a) smaller or equal (b) less than (c) greater than or equal (d) not equal
-
26.🔀 What number does this shop app show?
let total = 740;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What does this PIN rule show?
let pin = "881";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What number does this shop app show?
let total = 490;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 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 -
30.🔀 What number does this shop app show?
let total = 220;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 What does this PIN rule show?
let pin = "1445";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
32.🔀 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! -
33.🔀 What does this sign-up rule show?
let age = 13;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
34.🔀 What does this battery rule show?
let battery = 29;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
35.🔀 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 -
36.🔀 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 -
37.🔀 What number does this shop app show?
let total = 250;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 Which badge does this quiz app show?
let marks = 93;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
39.🔀 What does this battery rule show?
let battery = 60;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
40.🔀 What number does this shop app show?
let total = 370;
if (total > 500) {
total = total - 50;
}
show(total);
Answer key
- only one
- Silver
- pick one of two actions
- 270
- Welcome!
- Welcome!
- ===
- PIN saved
- 310
- Ask a parent
- 580
- when the test is false
- Use 4 digits
- 350
- Bronze
- 480
- Silver
- Use 4 digits
- Battery OK
- Welcome!
- 710
- Use 4 digits
- Ask a parent
- Battery OK
- greater than or equal
- 690
- Use 4 digits
- 490
- Welcome!
- 220
- PIN saved
- Ask a parent
- Welcome!
- Battery OK
- Battery OK
- Battery OK
- 250
- Gold
- Battery OK
- 370
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students