0
0
Typescriptprogramming~10 mins

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'
A1
B0
C'Up'
D"Up"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values instead of numbers for numeric enums.
Forgetting that numeric enums start at 0 by default.
2fill in blank
medium

Complete the code to get the numeric value of Direction.Left.

Typescript
let leftValue: number = Direction.[1];
Drag options to blanks, or click blank then click option'
ALeft
BRight
CUp
DDown
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong enum member name.
Using string values instead of enum members.
3fill in blank
hard

Fix the error in the code to get the enum member name from its numeric value.

Typescript
let directionName: string = Direction[[1]];
Drag options to blanks, or click blank then click option'
ADirection.Left
B'Left'
C2
D"Left"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string keys instead of numeric keys to index the enum.
Using enum member references instead of numbers.
4fill in blank
hard

Fill both blanks to declare a numeric enum with custom starting value and get its member value.

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

let activeValue = Status.[2];
Drag options to blanks, or click blank then click option'
A5
BActive
CInactive
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 5 for the starting value.
Accessing the wrong enum member.
5fill in blank
hard

Fill all three blanks to create a numeric enum and get the name of a member by its value.

Typescript
enum Color {
  Red = [1],
  Green,
  Blue
}

let colorValue = Color.[2];
let colorName = Color[[3]];
Drag options to blanks, or click blank then click option'
A10
BGreen
C11
DRed
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong numeric values for enum members.
Mixing up member names and values.