0
0
Typescriptprogramming~10 mins

Why enums are needed in Typescript - Test Your Understanding

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

Complete the code to declare an enum named Direction.

Typescript
enum Direction {
  Up = [1],
  Down,
  Left,
  Right
}
Drag options to blanks, or click blank then click option'
A0
B1
Ctrue
D"UP"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values instead of numbers without explicit string enums.
Starting enum values at 1 without specifying.
2fill in blank
medium

Complete the code to access the enum value for Direction.Left.

Typescript
const leftValue = Direction.[1];
Drag options to blanks, or click blank then click option'
ADown
BRight
CUp
DLeft
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or misspelled enum member names.
Trying to access enum values by number directly.
3fill in blank
hard

Fix the error in the enum declaration by completing the missing part.

Typescript
enum Status {
  Active = [1],
  Inactive,
  Pending
}
Drag options to blanks, or click blank then click option'
A"active"
B1
Ctrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values without quotes.
Using boolean values in enums.
4fill in blank
hard

Fill both blanks to create a function that returns a string based on enum input.

Typescript
function getStatusMessage(status: Status): string {
  switch(status) {
    case Status.Active:
      return [1];
    case Status.Inactive:
      return [2];
    default:
      return "Unknown";
  }
}
Drag options to blanks, or click blank then click option'
A"User is active"
B"User is inactive"
C"Active"
D"Inactive"
Attempts:
3 left
💡 Hint
Common Mistakes
Returning enum names instead of messages.
Mixing up messages for statuses.
5fill in blank
hard

Fill all three blanks to create a numeric enum and use it in a condition.

Typescript
enum Level {
  Low = [1],
  Medium,
  High
}

const currentLevel = Level.[2];

if (currentLevel > Level.[3]) {
  console.log("Level is above Low");
}
Drag options to blanks, or click blank then click option'
A0
BMedium
CLow
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values instead of numbers in numeric enums.
Comparing enum values incorrectly.