Complete the code to declare a const enum named Colors.
const enum [1] {
Red,
Green,
Blue
}The enum name should be Colors as declared.
Complete the code to access the enum value for Green.
const greenValue = Colors.[1];Accessing the Green member of the Colors enum returns its value.
Fix the error in the code to correctly use a const enum value in a function.
function getColorName(color: Colors): string {
return color === Colors.[1] ? 'Green' : 'Unknown';
}The function compares the input to Colors.Green to return the correct name.
Fill both blanks to create a const enum and use its value in a variable.
const enum [1] { Small = 1, Medium = 2, Large = 3 } const sizeValue = [2].Medium;
The enum is named Sizes and the variable accesses Sizes.Medium.
Fill all three blanks to declare a const enum, assign a value, and compare it in a condition.
const enum [1] { Low = 0, Medium = 1, High = 2 } const currentLevel = [2].High; if (currentLevel === [3].High) { console.log('High level reached'); }
The enum is declared as Level, but the variable and condition use Priority, which is incorrect. The correct consistent name is Priority for all blanks except the declaration which should be Level. The correct answer uses Level for declaration and Priority for usage, which is inconsistent. The correct consistent name for all is Priority. Here, the blanks are filled to show the correct usage with Priority.