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 PIN rule show?
let pin = "827";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
2.🔀 Which badge does this quiz app show?
let marks = 28;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
3.🔀 Which badge does this quiz app show?
let marks = 42;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver - 4.🔀 What does if / else let an app do? (a) save a photo (b) pick one of two actions (c) repeat forever (d) draw a screen
-
5.🔀 What number does this shop app show?
let total = 710;
if (total > 500) {
total = total - 50;
}
show(total); -
6.🔀 Which badge does this quiz app show?
let marks = 62;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
7.🔀 What does this PIN rule show?
let pin = "553";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits - 8.🔀 With if / else if / else, how many parts run? (a) two (b) only one (c) all of them (d) none
-
9.🔀 What does this sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Ask a parent (b) Welcome! -
10.🔀 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 -
11.🔀 Which badge does this quiz app show?
let marks = 27;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
12.🔀 What number does this shop app show?
let total = 270;
if (total > 500) {
total = total - 50;
}
show(total); -
13.🔀 What does this battery rule show?
let battery = 59;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
14.🔀 What number does this shop app show?
let total = 560;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 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 -
16.🔀 Which badge does this quiz app show?
let marks = 35;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
17.🔀 What number does this shop app show?
let total = 200;
if (total > 500) {
total = total - 50;
}
show(total); - 18.🔀 In this course’s code, which sign tests “is equal to”? (a) === (b) => (c) = (d) !==
-
19.🔀 Which badge does this quiz app show?
let marks = 57;
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 = 310;
if (total > 500) {
total = total - 50;
}
show(total); -
21.🔀 What does this battery rule show?
let battery = 5;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Battery OK (b) Low battery -
22.🔀 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 -
23.🔀 What does this PIN rule show?
let pin = "52599";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
24.🔀 What does this battery rule show?
let battery = 32;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
25.🔀 What does this battery rule show?
let battery = 40;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
26.🔀 What number does this shop app show?
let total = 470;
if (total > 500) {
total = total - 50;
}
show(total); -
27.🔀 What does this PIN rule show?
let pin = "39262";
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 = 900;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 What number does this shop app show?
let total = 810;
if (total > 500) {
total = total - 50;
}
show(total); - 30.🔀 What does >= mean? (a) less than (b) not equal (c) smaller or equal (d) greater than or equal
-
31.🔀 What does this sign-up rule show?
let age = 16;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
32.🔀 What does this PIN rule show?
let pin = "34103";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
33.🔀 What does this sign-up rule show?
let age = 12;
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 = 39;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
35.🔀 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! -
36.🔀 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 -
37.🔀 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) Bronze (b) Silver (c) Gold -
38.🔀 Which badge does this quiz app show?
let marks = 99;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Bronze (c) Gold -
39.🔀 What number does this shop app show?
let total = 640;
if (total > 500) {
total = total - 50;
}
show(total); -
40.🔀 Which badge does this quiz app show?
let marks = 34;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold
Answer key
- Use 4 digits
- Bronze
- Bronze
- pick one of two actions
- 660
- Silver
- Use 4 digits
- only one
- Ask a parent
- Welcome!
- Bronze
- 270
- Battery OK
- 510
- Battery OK
- Bronze
- 200
- ===
- Silver
- 310
- Low battery
- Welcome!
- Use 4 digits
- Battery OK
- Battery OK
- 470
- Use 4 digits
- 850
- 760
- greater than or equal
- Welcome!
- Use 4 digits
- Ask a parent
- Battery OK
- Ask a parent
- Battery OK
- Gold
- Gold
- 590
- Bronze
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students