0
0
PowerShellscripting~20 mins

Comparison operators (-eq, -ne, -gt, -lt) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell comparison?
Consider the following PowerShell code snippet. What will it output?
PowerShell
$a = 5
$b = 10
if ($a -lt $b) { "Less" } else { "Not Less" }
ANot Less
BLess
CTrue
DFalse
Attempts:
2 left
💡 Hint
Remember that -lt means 'less than'.
💻 Command Output
intermediate
2:00remaining
What does this script print?
What will this PowerShell script print to the console?
PowerShell
$x = 7
$y = 7
if ($x -ne $y) { "Different" } else { "Same" }
ASame
BDifferent
CTrue
DFalse
Attempts:
2 left
💡 Hint
The -ne operator means 'not equal'.
💻 Command Output
advanced
2:00remaining
What is the output of this comparison chain?
What will this PowerShell code output?
PowerShell
$num = 15
if ($num -gt 10 -and $num -lt 20) { "In range" } else { "Out of range" }
AIn range
BTrue
COut of range
DFalse
Attempts:
2 left
💡 Hint
Check if 15 is greater than 10 and less than 20.
💻 Command Output
advanced
2:00remaining
What error or output does this script produce?
What happens when you run this PowerShell code?
PowerShell
$val = '5'
if ($val -gt 3) { "Greater" } else { "Not Greater" }
AFalse
BNot Greater
CCannot compare values of different types
DGreater
Attempts:
2 left
💡 Hint
PowerShell tries to convert strings to numbers when comparing.
💻 Command Output
expert
3:00remaining
What is the output of this script with mixed comparisons?
Analyze this PowerShell script and select the output it produces.
PowerShell
$a = 8
$b = 8
$c = 10
if ($a -eq $b -and $c -lt 5) { "Match and less" } elseif ($a -eq $b -and $c -gt 5) { "Match and greater" } else { "No match" }
AError: ambiguous condition
BMatch and less
CMatch and greater
DNo match
Attempts:
2 left
💡 Hint
Check both conditions carefully in order.