Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a heterogeneous enum with a string and a number.
Typescript
enum Status {
Active = [1],
Inactive = 0
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a number without quotes for a string member.
Using boolean values in enums.
✗ Incorrect
The enum member 'Active' is assigned a string value "ACTIVE" to create a heterogeneous enum with both string and number values.
2fill in blank
mediumComplete the code to access the string value of the enum member.
Typescript
const currentStatus = Status.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the numeric value instead of the member name.
Using lowercase member names.
✗ Incorrect
Accessing 'Status.Active' returns the string value "ACTIVE" assigned in the enum.
3fill in blank
hardFix the error in the enum declaration to correctly mix string and number values.
Typescript
enum Response {
Yes = [1],
No = "NO"
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean or null values in enums.
Missing quotes for string values.
✗ Incorrect
Assigning the number 1 to 'Yes' allows the enum to be heterogeneous with string and number values.
4fill in blank
hardFill both blanks to create a heterogeneous enum with a string and a number.
Typescript
enum Direction {
Up = [1],
Down = [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning numbers as strings or vice versa.
Using the same type for both members.
✗ Incorrect
The enum 'Direction' has 'Up' as a string "UP" and 'Down' as a number 1, making it heterogeneous.
5fill in blank
hardFill all three blanks to create a heterogeneous enum with string and number values and access a member.
Typescript
enum Mode {
Read = [1],
Write = [2],
}
const modeValue = Mode.[3]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up member names and values when accessing.
Using numbers as strings or vice versa.
✗ Incorrect
The enum 'Mode' has 'Read' as string "READ" and 'Write' as number 1. Accessing 'Mode.Write' returns 1.