Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign the smaller number to min using the ternary operator.
C Sharp (C#)
int a = 5; int b = 10; int min = (a < b) ? [1] : b;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
b instead of a for the true part.Putting the condition inside the blank.
✗ Incorrect
The ternary operator checks if a < b. If true, it assigns a to min, otherwise b.
2fill in blank
mediumComplete the code to assign result as "Even" or "Odd" based on num.
C Sharp (C#)
int num = 7; string result = (num % 2 == 0) ? [1] : "Odd";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning "Odd" for the true part.
Using
num instead of a string.✗ Incorrect
The ternary operator checks if num is even. If true, it assigns "Even", else "Odd".
3fill in blank
hardFix the error in the ternary operator to assign status correctly.
C Sharp (C#)
int score = 85; string status = score >= 60 ? "Pass" [1] "Fail";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semicolon or comma instead of a colon.
Omitting the colon entirely.
✗ Incorrect
The ternary operator requires a colon : between the true and false expressions.
4fill in blank
hardFill both blanks to assign message based on age.
C Sharp (C#)
int age = 20; string message = (age >= [1]) ? "Adult" : [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 21 instead of 18 for the age check.
Using "Child" instead of "Minor" for the false part.
✗ Incorrect
If age is 18 or more, message is "Adult"; otherwise, it is "Minor".
5fill in blank
hardFill all three blanks to create a dictionary that maps numbers to "Even" or "Odd" strings.
C Sharp (C#)
var parity = new Dictionary<int, string>()
{
{1, [1],
{2, [2],
{3, [3]
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning "Even" to odd numbers.
Mixing up the order of values.
✗ Incorrect
Numbers 1 and 3 are odd, so map to "Odd"; number 2 is even, so map to "Even".