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.🔀 Which badge does this quiz app show?
let marks = 98;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
2.🔀 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) Gold (b) Silver (c) Bronze -
3.🔀 What number does this shop app show?
let total = 530;
if (total > 500) {
total = total - 50;
}
show(total); -
4.🔀 What does this PIN rule show?
let pin = "7925";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
5.🔀 What does this PIN rule show?
let pin = "315";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
6.🔀 What does this sign-up rule show?
let age = 8;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
7.🔀 Which badge does this quiz app show?
let marks = 92;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold - 8.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) all of them (d) only one
-
9.🔀 What does this PIN rule show?
let pin = "11028";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
10.🔀 Which badge does this quiz app show?
let marks = 85;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
11.🔀 What does this battery rule show?
let battery = 9;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
12.🔀 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 - 13.🔀 What does if / else let an app do? (a) draw a screen (b) save a photo (c) pick one of two actions (d) repeat forever
-
14.🔀 What does this battery rule show?
let battery = 75;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
15.🔀 What does this PIN rule show?
let pin = "52625";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
16.🔀 What does this battery rule show?
let battery = 50;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
17.🔀 What does this battery rule show?
let battery = 89;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
18.🔀 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) Gold (b) Silver (c) Bronze -
19.🔀 What does this battery rule show?
let battery = 12;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
20.🔀 What does this battery rule show?
let battery = 78;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
21.🔀 What number does this shop app show?
let total = 750;
if (total > 500) {
total = total - 50;
}
show(total); -
22.🔀 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! -
23.🔀 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 -
24.🔀 What does this battery rule show?
let battery = 44;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
25.🔀 What does this PIN rule show?
let pin = "1943";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
26.🔀 What does this battery rule show?
let battery = 30;
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 = 31;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
28.🔀 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 -
29.🔀 What does this battery rule show?
let battery = 91;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
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 = "84413";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
32.🔀 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! - 33.🔀 What does >= mean? (a) not equal (b) less than (c) greater than or equal (d) smaller or equal
-
34.🔀 What does this PIN rule show?
let pin = "214";
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 = "12565";
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 = "741";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
37.🔀 What number does this shop app show?
let total = 520;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this PIN rule show?
let pin = "241";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 What number does this shop app show?
let total = 840;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this PIN rule show?
let pin = "79553";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved
Answer key
- Gold
- Bronze
- 480
- PIN saved
- Use 4 digits
- Ask a parent
- Gold
- only one
- Use 4 digits
- Gold
- Low battery
- Ask a parent
- pick one of two actions
- Battery OK
- Use 4 digits
- Battery OK
- Battery OK
- Silver
- Low battery
- Battery OK
- 700
- Welcome!
- Low battery
- Battery OK
- PIN saved
- Battery OK
- Bronze
- Battery OK
- Battery OK
- 220
- Use 4 digits
- Welcome!
- greater than or equal
- Use 4 digits
- Use 4 digits
- Use 4 digits
- 470
- Use 4 digits
- 790
- Use 4 digits
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students