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 = 55;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
2.🔀 What does this PIN rule show?
let pin = "580";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
3.🔀 Which badge does this quiz app show?
let marks = 43;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold - 4.🔀 With if / else if / else, how many parts run? (a) only one (b) all of them (c) two (d) none
-
5.🔀 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) Silver (b) Gold (c) Bronze -
6.🔀 What number does this shop app show?
let total = 220;
if (total > 500) {
total = total - 50;
}
show(total); -
7.🔀 What number does this shop app show?
let total = 490;
if (total > 500) {
total = total - 50;
}
show(total); -
8.🔀 What number does this shop app show?
let total = 400;
if (total > 500) {
total = total - 50;
}
show(total); - 9.🔀 What does if / else let an app do? (a) repeat forever (b) pick one of two actions (c) save a photo (d) draw a screen
-
10.🔀 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! -
11.🔀 What does this battery rule show?
let battery = 17;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
12.🔀 Which badge does this quiz app show?
let marks = 53;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
13.🔀 What number does this shop app show?
let total = 620;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What does this PIN rule show?
let pin = "987";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
15.🔀 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) Gold (b) Bronze (c) Silver - 16.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) === (c) !== (d) =>
-
17.🔀 What number does this shop app show?
let total = 380;
if (total > 500) {
total = total - 50;
}
show(total); -
18.🔀 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 -
19.🔀 Which badge does this quiz app show?
let marks = 47;
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 = 350;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 What does this PIN rule show?
let pin = "71731";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
22.🔀 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! -
23.🔀 What number does this shop app show?
let total = 210;
if (total > 500) {
total = total - 50;
}
show(total); - 24.🔀 What does >= mean? (a) less than (b) smaller or equal (c) greater than or equal (d) not equal
-
25.🔀 What does this PIN rule show?
let pin = "978";
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 = 6;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
27.🔀 What does this PIN rule show?
let pin = "2918";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
28.🔀 What does this PIN rule show?
let pin = "85014";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
29.🔀 What does this PIN rule show?
let pin = "16061";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
30.🔀 Which badge does this quiz app show?
let marks = 32;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
31.🔀 Which badge does this quiz app show?
let marks = 51;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
32.🔀 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 -
33.🔀 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 -
34.🔀 What does this PIN rule show?
let pin = "355";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
35.🔀 What number does this shop app show?
let total = 530;
if (total > 500) {
total = total - 50;
}
show(total); -
36.🔀 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 -
37.🔀 What number does this shop app show?
let total = 230;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this battery rule show?
let battery = 36;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
39.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 What does this battery rule show?
let battery = 38;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery
Answer key
- Silver
- Use 4 digits
- Bronze
- only one
- Silver
- 220
- 490
- 400
- pick one of two actions
- Welcome!
- Low battery
- Silver
- 570
- Use 4 digits
- Silver
- ===
- 380
- Welcome!
- Bronze
- 350
- Use 4 digits
- Ask a parent
- 210
- greater than or equal
- Use 4 digits
- Low battery
- PIN saved
- Use 4 digits
- Use 4 digits
- Bronze
- Silver
- Low battery
- Battery OK
- Use 4 digits
- 480
- Silver
- 230
- Battery OK
- 800
- Battery OK
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students