Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a string enum named Color with a member Red assigned to the string "RED".
Typescript
enum Color {
Red = [1]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string value.
Using the enum member name without quotes as the value.
✗ Incorrect
In TypeScript, string enum members must be assigned string literals, so
Red = "RED" is correct.2fill in blank
mediumComplete the code to access the string value of the enum member Color.Green.
Typescript
enum Color {
Green = "GREEN"
}
const greenValue: string = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call the enum member as a function.
Using bracket notation without quotes.
✗ Incorrect
To get the string value of an enum member, use dot notation like
Color.Green.3fill in blank
hardFix the error in the enum declaration by completing the code to assign string values correctly.
Typescript
enum Direction {
Up = [1],
Down = "DOWN"
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted identifiers as string values.
Mixing single and double quotes inconsistently.
✗ Incorrect
Enum string members must be assigned string literals with quotes, so
Up = "UP" is correct.4fill in blank
hardFill both blanks to create a string enum Status with members Active and Inactive assigned to "ACTIVE" and "INACTIVE" respectively.
Typescript
enum Status {
Active = [1],
Inactive = [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes inconsistently.
Swapping the values between members.
✗ Incorrect
Enum members must be assigned string literals. Here,
Active is assigned "ACTIVE" and Inactive is assigned "INACTIVE".5fill in blank
hardFill all three blanks to create a string enum Response with members Yes, No, and Maybe assigned to "YES", "NO", and "MAYBE" respectively.
Typescript
enum Response {
Yes = [1],
No = [2],
Maybe = [3]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the string values for members.
Using incorrect strings like "NOPE".
✗ Incorrect
Assign the correct string literals to each enum member as specified:
Yes = "YES", No = "NO", and Maybe = "MAYBE".