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 = "1860";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
2.🔀 What does this PIN rule show?
let pin = "4596";
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 = 83;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Bronze (c) Silver -
4.🔀 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 -
5.🔀 What does this PIN rule show?
let pin = "5839";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
6.🔀 What does this PIN rule show?
let pin = "97703";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
7.🔀 What does this PIN rule show?
let pin = "40750";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
8.🔀 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! -
9.🔀 What number does this shop app show?
let total = 880;
if (total > 500) {
total = total - 50;
}
show(total); - 10.🔀 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
- 11.🔀 In this course’s code, which sign tests “is equal to”? (a) = (b) => (c) !== (d) ===
-
12.🔀 Which badge does this quiz app show?
let marks = 33;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Silver (b) Gold (c) Bronze -
13.🔀 What number does this shop app show?
let total = 410;
if (total > 500) {
total = total - 50;
}
show(total); -
14.🔀 What number does this shop app show?
let total = 280;
if (total > 500) {
total = total - 50;
}
show(total); -
15.🔀 Which badge does this quiz app show?
let marks = 58;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze -
16.🔀 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! - 17.🔀 What does >= mean? (a) smaller or equal (b) less than (c) not equal (d) greater than or equal
-
18.🔀 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) Gold (c) Silver -
19.🔀 What does this sign-up rule show?
let age = 10;
if (age >= 13) {
show("Welcome!");
} else {
show("Ask a parent");
} (a) Welcome! (b) Ask a parent -
20.🔀 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 -
21.🔀 What does this PIN rule show?
let pin = "2063";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
22.🔀 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) Silver (b) Bronze (c) Gold -
23.🔀 What does this PIN rule show?
let pin = "765";
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 = 800;
if (total > 500) {
total = total - 50;
}
show(total); -
25.🔀 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) Gold (c) Silver -
26.🔀 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! -
27.🔀 What does this PIN rule show?
let pin = "321";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
28.🔀 What number does this shop app show?
let total = 600;
if (total > 500) {
total = total - 50;
}
show(total); -
29.🔀 What does this battery rule show?
let battery = 62;
if (battery < 20) {
show("Low battery");
} else {
show("Battery OK");
} (a) Low battery (b) Battery OK -
30.🔀 What does this PIN rule show?
let pin = "65559";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) PIN saved (b) Use 4 digits -
31.🔀 What number does this shop app show?
let total = 550;
if (total > 500) {
total = total - 50;
}
show(total); -
32.🔀 What number does this shop app show?
let total = 870;
if (total > 500) {
total = total - 50;
}
show(total); - 33.🔀 With if / else if / else, how many parts run? (a) none (b) two (c) all of them (d) only one
-
34.🔀 What number does this shop app show?
let total = 340;
if (total > 500) {
total = total - 50;
}
show(total); -
35.🔀 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! -
36.🔀 Which badge does this quiz app show?
let marks = 74;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Gold (c) Silver -
37.🔀 What number does this shop app show?
let total = 850;
if (total > 500) {
total = total - 50;
}
show(total); -
38.🔀 What does this PIN rule show?
let pin = "3024";
if (pin.length === 4) {
show("PIN saved");
} else {
show("Use 4 digits");
} (a) Use 4 digits (b) PIN saved -
39.🔀 Which badge does this quiz app show?
let marks = 63;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Bronze (b) Silver (c) Gold -
40.🔀 Which badge does this quiz app show?
let marks = 54;
if (marks >= 80) {
show("Gold");
} else if (marks >= 50) {
show("Silver");
} else {
show("Bronze");
} (a) Gold (b) Silver (c) Bronze
Answer key
- PIN saved
- PIN saved
- Gold
- Bronze
- PIN saved
- Use 4 digits
- Use 4 digits
- Ask a parent
- 830
- pick one of two actions
- ===
- Bronze
- 410
- 280
- Silver
- Welcome!
- greater than or equal
- Bronze
- Ask a parent
- Battery OK
- PIN saved
- Bronze
- Use 4 digits
- 750
- Bronze
- Welcome!
- Use 4 digits
- 550
- Battery OK
- Use 4 digits
- 500
- 820
- only one
- 340
- Welcome!
- Silver
- 800
- PIN saved
- Silver
- Silver
Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students