Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable value equals 10 using a constant pattern.
C Sharp (C#)
if (value is [1]) { Console.WriteLine("Value is 10"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Using the variable name instead of a constant.
Using a boolean value instead of a constant.
✗ Incorrect
The constant pattern checks if the variable matches the constant value 10.
2fill in blank
mediumComplete the code to print a message when input equals the character 'A' using a constant pattern.
C Sharp (C#)
if (input is [1]) { Console.WriteLine("Input is A"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes which makes it a string.
Using uppercase without quotes.
Using lowercase character instead of uppercase.
✗ Incorrect
The constant pattern for a character uses single quotes around the character.
3fill in blank
hardFix the error in the code to correctly check if status equals the boolean constant true using a constant pattern.
C Sharp (C#)
if (status is [1]) { Console.WriteLine("Status is true"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase True or TRUE which are invalid.
Using quotes which makes it a string.
Using incorrect casing.
✗ Incorrect
The boolean constant true is lowercase in C# and used directly in the pattern.
4fill in blank
hardFill both blanks to check if number is either 0 or 1 using constant patterns in a switch expression.
C Sharp (C#)
string result = number switch {
[1] => "Zero",
[2] => "One",
_ => "Other"
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string constants instead of numeric constants.
Mixing quotes and no quotes incorrectly.
Using wrong numbers.
✗ Incorrect
Use numeric constants 0 and 1 without quotes for constant patterns in switch expressions.
5fill in blank
hardFill all three blanks to create a switch expression that returns a message for grade being 'A', 'B', or any other character using constant patterns.
C Sharp (C#)
string message = grade switch {
[1] => "Excellent",
[2] => "Good",
[3] => "Needs Improvement"
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes for characters.
Not using the discard pattern for the default case.
Using wrong characters.
✗ Incorrect
Use character constants with single quotes for 'A' and 'B', and the discard pattern '_' for any other value.