Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values instead of numbers without explicit string enums.
Starting enum values at 1 without specifying.
✗ Incorrect
Enums start numbering from 0 by default unless specified otherwise.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or misspelled enum member names.
Trying to access enum values by number directly.
✗ Incorrect
You access enum members by their names, like Direction.Left.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values without quotes.
Using boolean values in enums.
✗ Incorrect
Enum numeric values must be numbers. Using 1 starts numbering from 1.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning enum names instead of messages.
Mixing up messages for statuses.
✗ Incorrect
The function returns descriptive messages for each enum status.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string values instead of numbers in numeric enums.
Comparing enum values incorrectly.
✗ Incorrect
The enum starts at 0 for Low, Medium is next, and the condition checks if currentLevel is above Low.