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 = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent - 2.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) none (d) all of them
-
3.🔀 What number does this shop app show?
let total = 510;
if (total > 500) {
total = total - 50;
}
show(total); -
4.🔀 What does this PIN rule show?
let pin = "96558";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
5.🔀 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! -
6.🔀 What does this battery rule show?
let battery = 61;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
7.🔀 Which badge does this quiz app show?
let marks = 22;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver - 8.🔀 What does >= mean? (a) smaller or equal (b) not equal (c) less than (d) greater than or equal
-
9.🔀 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! -
10.🔀 Which badge does this quiz app show?
let marks = 30;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze - 11.🔀 What does if / else let an app do? (a) pick one of two actions (b) save a photo (c) draw a screen (d) repeat forever
-
12.🔀 What does this PIN rule show?
let pin = "140";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
13.🔀 What does this battery rule show?
let battery = 50;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
14.🔀 What does this PIN rule show?
let pin = "168";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
15.🔀 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! -
16.🔀 What number does this shop app show?
let total = 870;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 What number does this shop app show?
let total = 260;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 What does this PIN rule show?
let pin = "162";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 19.🔀 In this course’s code, which sign tests “is equal to”? (a) => (b) === (c) !== (d) =
-
20.🔀 What does this battery rule show?
let battery = 14;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
21.🔀 What does this PIN rule show?
let pin = "3541";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
22.🔀 What does this PIN rule show?
let pin = "3364";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
23.🔀 What does this PIN rule show?
let pin = "4175";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
24.🔀 What does this PIN rule show?
let pin = "81324";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
25.🔀 What number does this shop app show?
let total = 240;
if (total > 500) {
total = total - 50;
}
show(total); -
26.🔀 What does this PIN rule show?
let pin = "5263";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
27.🔀 What number does this shop app show?
let total = 790;
if (total > 500) {
total = total - 50;
}
show(total); -
28.🔀 Which badge does this quiz app show?
let marks = 91;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
29.🔀 Which badge does this quiz app show?
let marks = 97;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
30.🔀 What number does this shop app show?
let total = 270;
if (total > 500) {
total = total - 50;
}
show(total); -
31.🔀 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) Silver (b) Bronze (c) Gold -
32.🔀 What does this PIN rule show?
let pin = "51086";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
33.🔀 What number does this shop app show?
let total = 680;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this PIN rule show?
let pin = "16970";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What does this battery rule show?
let battery = 5;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
36.🔀 What does this PIN rule show?
let pin = "52487";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
37.🔀 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 -
38.🔀 What does this PIN rule show?
let pin = "201";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 39.🔀 When does the else part run? (a) never (b) when the test is false (c) when the test is true (d) always
-
40.🔀 What does this battery rule show?
let battery = 41;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- Welcome!
- only one
- 460
- Use 4 digits
- Welcome!
- Battery OK
- Bronze
- greater than or equal
- Ask a parent
- Bronze
- pick one of two actions
- Use 4 digits
- Battery OK
- Use 4 digits
- Ask a parent
- 820
- 260
- Use 4 digits
- ===
- Low battery
- PIN saved
- PIN saved
- PIN saved
- Use 4 digits
- 240
- PIN saved
- 740
- Gold
- Gold
- 270
- Silver
- Use 4 digits
- 630
- Use 4 digits
- Low battery
- Use 4 digits
- Bronze
- Use 4 digits
- when the test is false
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students