Complete the code to declare an enum named Direction.
enum Direction {
Up = [1],
Down,
Left,
Right
}Enums start numbering from 0 by default unless specified otherwise.
Complete the code to access the enum value for Direction.Left.
const leftValue = Direction.[1];You access enum members by their names, like Direction.Left.
Fix the error in the enum declaration by completing the missing part.
enum Status {
Active = [1],
Inactive,
Pending
}Enum numeric values must be numbers. Using 1 starts numbering from 1.
Fill both blanks to create a function that returns a string based on enum input.
function getStatusMessage(status: Status): string {
switch(status) {
case Status.Active:
return [1];
case Status.Inactive:
return [2];
default:
return "Unknown";
}
}The function returns descriptive messages for each enum status.
Fill all three blanks to create a numeric enum and use it in a condition.
enum Level {
Low = [1],
Medium,
High
}
const currentLevel = Level.[2];
if (currentLevel > Level.[3]) {
console.log("Level is above Low");
}The enum starts at 0 for Low, Medium is next, and the condition checks if currentLevel is above Low.
