Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an enum named Color.
C Sharp (C#)
enum [1] { Red, Green, Blue } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural form like 'Colors' instead of singular 'Color'.
Using lowercase names which is not a C# convention.
✗ Incorrect
The enum is named Color to represent colors.
2fill in blank
mediumComplete the switch expression to return the string name of the color.
C Sharp (C#)
string GetColorName(Color color) => color switch { Color.Red => [1], _ => "Unknown" }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the enum member itself instead of a string.
Using single quotes which are for characters, not strings.
✗ Incorrect
The switch expression returns the string "Red" for Color.Red.
3fill in blank
hardFix the error in the switch expression to handle all enum values.
C Sharp (C#)
string GetColorName(Color color) => color switch { Color.Red => "Red", Color.Green => [1], Color.Blue => "Blue", _ => "Unknown" }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the enum member instead of a string.
Using single quotes instead of double quotes.
✗ Incorrect
The switch expression must return the string "Green" for Color.Green.
4fill in blank
hardFill both blanks to complete the switch expression that returns a message for each color.
C Sharp (C#)
string GetColorMessage(Color color) => color switch { Color.Red => [1], Color.Green => [2], _ => "Color not recognized" }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up messages for colors.
Forgetting to use quotes around the messages.
✗ Incorrect
The messages correspond to the colors: Red means "Stop!" and Green means "Go!".
5fill in blank
hardFill all three blanks to create a switch expression that returns the color's hex code.
C Sharp (C#)
string GetColorHex(Color color) => color switch { Color.Red => [1], Color.Green => [2], Color.Blue => [3], _ => "#000000" }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up hex codes for colors.
Using quotes incorrectly or missing them.
✗ Incorrect
The hex codes represent the colors: Red is #FF0000, Green is #00FF00, and Blue is #0000FF.