0
0
Typescriptprogramming~10 mins

String enums in Typescript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"RED"
BRED
C'Red'
DRed
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string value.
Using the enum member name without quotes as the value.
2fill in blank
medium

Complete 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'
AColor[Green]
BColor.Green
CColor.Green()
DColor['Green']()
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call the enum member as a function.
Using bracket notation without quotes.
3fill in blank
hard

Fix 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'
AUP
BUp
C"UP"
D'Up'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted identifiers as string values.
Mixing single and double quotes inconsistently.
4fill in blank
hard

Fill 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'
A"ACTIVE"
B"INACTIVE"
C'INACTIVE'
D'ACTIVE'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes inconsistently.
Swapping the values between members.
5fill in blank
hard

Fill 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'
A"NO"
B"YES"
C"MAYBE"
D"NOPE"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the string values for members.
Using incorrect strings like "NOPE".