0
0
C Sharp (C#)programming~10 mins

Ternary conditional operator in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A5
Ba
Cb
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using b instead of a for the true part.
Putting the condition inside the blank.
2fill in blank
medium

Complete 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'
A"Even"
B"Odd"
Cnum
D"Number"
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning "Odd" for the true part.
Using num instead of a string.
3fill in blank
hard

Fix 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'
A?
B;
C,
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semicolon or comma instead of a colon.
Omitting the colon entirely.
4fill in blank
hard

Fill 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'
A18
B"Minor"
C"Child"
D21
Attempts:
3 left
💡 Hint
Common Mistakes
Using 21 instead of 18 for the age check.
Using "Child" instead of "Minor" for the false part.
5fill in blank
hard

Fill 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'
A"Odd"
B"Even"
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning "Even" to odd numbers.
Mixing up the order of values.