Complete the code to declare a simple enum named Color with values Red, Green, and Blue.
export enum Color {
Red = 0,
Green = 1,
[1] = 2
}The enum Color includes Blue as the third value with the numeric value 2.
Complete the code to use the enum Color and assign the value Green to the variable selectedColor.
import { Color } from './color.enum'; const selectedColor: Color = [1];
The variable selectedColor is assigned the enum value Color.Green.
Fix the error in the enum declaration by completing the missing enum member name.
export enum Direction {
Up = 1,
Down = 2,
[1] = 3,
Left = 4
}The enum Direction includes Right as the member with value 3.
Fill both blanks to create an enum Status with string values Active and Inactive.
export enum Status {
Active = '[1]',
Inactive = '[2]'
}The enum Status uses string values 'active' and 'inactive' for its members.
Fill all three blanks to create a function getStatusMessage that returns a message based on the Status enum value.
import { Status } from './status.enum'; function getStatusMessage(status: Status): string { switch (status) { case Status.[1]: return '[2]'; case Status.[3]: return 'User is inactive'; default: return 'Unknown status'; } }
The function checks if the status is Status.Active and returns 'User is active'. For Status.Inactive, it returns 'User is inactive'.