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 if / else let an app do? (a) repeat forever (b) draw a screen (c) save a photo (d) pick one of two actions
-
2.🔀 What number does this shop app show?
let total = 800;
if (total > 500) {
total = total - 50;
}
show(total); -
3.🔀 Which badge does this quiz app show?
let marks = 36;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
4.🔀 What does this PIN rule show?
let pin = "97616";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
5.🔀 What number does this shop app show?
let total = 290;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 What number does this shop app show?
let total = 270;
if (total > 500) {
total = total - 50;
}
show(total); - 7.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) all of them (d) only one
-
8.🔀 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 -
9.🔀 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 -
10.🔀 Which badge does this quiz app show?
let marks = 48;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
11.🔀 What does this sign-up rule show?
let age = 15;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! - 12.🔀 When does the else part run? (a) never (b) when the test is false (c) when the test is true (d) always
-
13.🔀 Which badge does this quiz app show?
let marks = 23;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
14.🔀 What number does this shop app show?
let total = 400;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 What does this PIN rule show?
let pin = "64874";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
16.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
17.🔀 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! -
18.🔀 What does this PIN rule show?
let pin = "8335";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
19.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
20.🔀 What does this PIN rule show?
let pin = "19525";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
21.🔀 What does this PIN rule show?
let pin = "644";
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 = "771";
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 = "18590";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
24.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 Which badge does this quiz app show?
let marks = 20;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
26.🔀 What does this PIN rule show?
let pin = "498";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
27.🔀 What does this battery rule show?
let battery = 46;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
28.🔀 What does this PIN rule show?
let pin = "164";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
29.🔀 What number does this shop app show?
let total = 870;
if (total > 500) {
total = total - 50;
}
show(total); -
30.🔀 What does this PIN rule show?
let pin = "33806";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 What does this PIN rule show?
let pin = "21123";
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 = 13;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
33.🔀 What number does this shop app show?
let total = 360;
if (total > 500) {
total = total - 50;
}
show(total); -
34.🔀 What does this PIN rule show?
let pin = "603";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
35.🔀 What does this PIN rule show?
let pin = "928";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
36.🔀 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! -
37.🔀 What number does this shop app show?
let total = 460;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this PIN rule show?
let pin = "92175";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved - 39.🔀 What does >= mean? (a) greater than or equal (b) not equal (c) smaller or equal (d) less than
-
40.🔀 What does this battery rule show?
let battery = 4;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- pick one of two actions
- 750
- Bronze
- Use 4 digits
- 290
- 270
- only one
- Ask a parent
- Welcome!
- Bronze
- Welcome!
- when the test is false
- Bronze
- 400
- Use 4 digits
- 510
- Welcome!
- PIN saved
- 590
- Use 4 digits
- Use 4 digits
- Use 4 digits
- Use 4 digits
- 800
- Bronze
- Use 4 digits
- Battery OK
- Use 4 digits
- 820
- Use 4 digits
- Use 4 digits
- Welcome!
- 360
- Use 4 digits
- Use 4 digits
- Welcome!
- 460
- Use 4 digits
- greater than or equal
- Low battery
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students