0
0
Typescriptprogramming~10 mins

Heterogeneous enums in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"1"
B1
Ctrue
D"ACTIVE"
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a number without quotes for a string member.
Using boolean values in enums.
2fill in blank
medium

Complete 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'
AInactive
B0
CActive
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the numeric value instead of the member name.
Using lowercase member names.
3fill in blank
hard

Fix 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'
Anull
B1
Ctrue
D"YES"
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean or null values in enums.
Missing quotes for string values.
4fill in blank
hard

Fill 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'
A"UP"
B0
C1
D"DOWN"
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning numbers as strings or vice versa.
Using the same type for both members.
5fill in blank
hard

Fill 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'
A"READ"
B2
CWrite
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up member names and values when accessing.
Using numbers as strings or vice versa.