0
0
Typescriptprogramming~10 mins

Reverse mapping in numeric 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 numeric enum named Direction.

Typescript
enum Direction {
  Up = [1],
  Down,
  Left,
  Right
}
Drag options to blanks, or click blank then click option'
A0
B1
C10
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 1 to the first member, which changes the default numbering.
Leaving the first member unassigned but expecting it to start at 1.
2fill in blank
medium

Complete the code to get the name of the enum member with value 2.

Typescript
let directionName = Direction[[1]];
Drag options to blanks, or click blank then click option'
A"Up"
B"Left"
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the string name instead of the numeric value for reverse mapping.
Using a value not defined in the enum.
3fill in blank
hard

Fix the error in accessing the enum member name by value.

Typescript
console.log(Direction[[1]]);
Drag options to blanks, or click blank then click option'
A4
B1
C"Right"
D"Down"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a numeric value for reverse mapping.
Using a numeric value not assigned to any enum member.
4fill in blank
hard

Fill both blanks to create a reverse mapping lookup for the enum member with value 3.

Typescript
const value = [1];
const name = Direction[[2]];
Drag options to blanks, or click blank then click option'
A3
B2
Cvalue
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong numeric value that does not correspond to any member.
Using a literal number instead of the variable in the second blank.
5fill in blank
hard

Fill all three blanks to declare a numeric enum with custom start, then get the name of the member with value 101.

Typescript
enum Status {
  Active = [1],
  Inactive,
  Pending
}

const code = [2];
const statusName = Status[[3]];
Drag options to blanks, or click blank then click option'
A100
B101
Ccode
D102
Attempts:
3 left
💡 Hint
Common Mistakes
Starting enum at 0 instead of 100.
Using the numeric value directly instead of the variable in the last blank.