0
0
Typescriptprogramming~10 mins

Const enums and optimization 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 const enum named Colors.

Typescript
const enum [1] {
  Red,
  Green,
  Blue
}
Drag options to blanks, or click blank then click option'
AEnumColors
BColorList
CPalette
DColors
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than the one declared.
Forgetting to use 'const' before enum.
2fill in blank
medium

Complete the code to access the enum value for Green.

Typescript
const greenValue = Colors.[1];
Drag options to blanks, or click blank then click option'
ABlue
BGreen
CRed
DYellow
Attempts:
3 left
💡 Hint
Common Mistakes
Using a member name that does not exist in the enum.
Using incorrect casing for the member name.
3fill in blank
hard

Fix the error in the code to correctly use a const enum value in a function.

Typescript
function getColorName(color: Colors): string {
  return color === Colors.[1] ? 'Green' : 'Unknown';
}
Drag options to blanks, or click blank then click option'
ABlue
BRed
CGreen
DYellow
Attempts:
3 left
💡 Hint
Common Mistakes
Using a member that does not match the returned string.
Using a non-existent enum member.
4fill in blank
hard

Fill both blanks to create a const enum and use its value in a variable.

Typescript
const enum [1] {
  Small = 1,
  Medium = 2,
  Large = 3
}

const sizeValue = [2].Medium;
Drag options to blanks, or click blank then click option'
ASizes
BColors
DShapes
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the enum declaration and usage.
Using unrelated enum names.
5fill in blank
hard

Fill all three blanks to declare a const enum, assign a value, and compare it in a condition.

Typescript
const enum [1] {
  Low = 0,
  Medium = 1,
  High = 2
}

const currentLevel = [2].High;

if (currentLevel === [3].High) {
  console.log('High level reached');
}
Drag options to blanks, or click blank then click option'
APriority
DLevel
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for enum declaration and usage.
Mismatching enum names in condition and assignment.