0
0
Angularframework~10 mins

Enums in Angular applications - 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 simple enum named Color with values Red, Green, and Blue.

Angular
export enum Color {
  Red = 0,
  Green = 1,
  [1] = 2
}
Drag options to blanks, or click blank then click option'
ABlue
BYellow
COrange
DPurple
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color name not declared in the enum.
Skipping the enum member name and only writing the number.
2fill in blank
medium

Complete the code to use the enum Color and assign the value Green to the variable selectedColor.

Angular
import { Color } from './color.enum';

const selectedColor: Color = [1];
Drag options to blanks, or click blank then click option'
AColor.Green
BColor.Blue
CColor.Red
DColor.Yellow
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a string instead of an enum member.
Using a member not declared in the enum.
3fill in blank
hard

Fix the error in the enum declaration by completing the missing enum member name.

Angular
export enum Direction {
  Up = 1,
  Down = 2,
  [1] = 3,
  Left = 4
}
Drag options to blanks, or click blank then click option'
ABack
BForward
CSide
DRight
Attempts:
3 left
💡 Hint
Common Mistakes
Using a direction name not matching the enum pattern.
Leaving the member name blank or using a number only.
4fill in blank
hard

Fill both blanks to create an enum Status with string values Active and Inactive.

Angular
export enum Status {
  Active = '[1]',
  Inactive = '[2]'
}
Drag options to blanks, or click blank then click option'
Aactive
Binactive
Cenabled
Ddisabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase strings instead of lowercase.
Mixing unrelated strings like 'enabled' or 'disabled'.
5fill in blank
hard

Fill all three blanks to create a function getStatusMessage that returns a message based on the Status enum value.

Angular
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';
  }
}
Drag options to blanks, or click blank then click option'
AActive
BUser is active
CInactive
DUser is enabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong enum member names in the switch cases.
Returning messages that do not match the status.