Challenge - 5 Problems
Logical Patterns Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of combined logical operators
What is the output of this C# code snippet?
C Sharp (C#)
bool a = true; bool b = false; bool c = true; if (a && b || c) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }
Attempts:
2 left
💡 Hint
Remember that && has higher precedence than || in C#.
✗ Incorrect
The expression a && b || c is evaluated as (a && b) || c. Since a && b is false and c is true, the overall expression is true. So, "Yes" is printed.
❓ Predict Output
intermediate2:00remaining
Result of negation with logical operators
What will be printed by this C# code?
C Sharp (C#)
bool x = false; bool y = true; if (!(x || y) && y) { Console.WriteLine("True branch"); } else { Console.WriteLine("False branch"); }
Attempts:
2 left
💡 Hint
Evaluate the expression inside the negation first.
✗ Incorrect
The expression !(x || y) && y becomes !(false || true) && true which is !true && true → false && true → false. So the else branch runs.
🔧 Debug
advanced3:00remaining
Identify the logical error in condition
This code is intended to print "Access granted" only if the user is an admin and is active. What is wrong with the condition?
C Sharp (C#)
bool isAdmin = true; bool isActive = false; if (isAdmin || isActive) { Console.WriteLine("Access granted"); } else { Console.WriteLine("Access denied"); }
Attempts:
2 left
💡 Hint
Think about when access should be granted.
✗ Incorrect
The condition isAdmin || isActive allows access if either is true. The requirement is both must be true, so it should be isAdmin && isActive.
📝 Syntax
advanced2:00remaining
Identify the syntax error in logical expression
Which option contains a syntax error in the logical expression?
Attempts:
2 left
💡 Hint
Check for missing parentheses.
✗ Incorrect
Option B is missing a closing parenthesis before the opening brace, causing a syntax error.
🚀 Application
expert3:00remaining
Determine the number of true conditions
Given the following code, how many times will "Condition met" be printed?
C Sharp (C#)
bool[] flags = { true, false, true, false, true };
int count = 0;
foreach (bool flag in flags)
{
if (flag && !(!flag || false))
{
Console.WriteLine("Condition met");
count++;
}
}
Console.WriteLine(count);Attempts:
2 left
💡 Hint
Simplify the condition inside the if statement.
✗ Incorrect
The condition flag && !(!flag || false) simplifies to flag && flag which is just flag. So it prints once for each true in the array, which are 3 times.