Challenge - 5 Problems
Logical Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell command?
Consider the following command:
What will this output?
Write-Output ($true -and $false) -or $true
What will this output?
PowerShell
Write-Output ($true -and $false) -or $true
Attempts:
2 left
💡 Hint
Remember that -and has higher precedence than -or in PowerShell.
✗ Incorrect
The expression evaluates ($true -and $false) first, which is False. Then False -or $true is True, so the output is True.
💻 Command Output
intermediate2:00remaining
What does this PowerShell expression output?
Evaluate this expression:
What is the output?
Write-Output -not ($false -or $false)
What is the output?
PowerShell
Write-Output -not ($false -or $false)
Attempts:
2 left
💡 Hint
Check what ($false -or $false) evaluates to before applying -not.
✗ Incorrect
($false -or $false) is False, so -not False is True. The output is True.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in PowerShell?
Identify the option that will cause a syntax error when run in PowerShell:
Attempts:
2 left
💡 Hint
Check the correct usage of the -not operator in PowerShell.
✗ Incorrect
Option A uses 'not' without the dash, which is invalid syntax in PowerShell. The correct operator is '-not'.
🔧 Debug
advanced2:00remaining
Why does this PowerShell script output 'True' instead of 'False'?
Given this script:
Why does it output 'True' instead of 'False'?
$a = $true
$b = $false
if ($a -or $b -and $false) { Write-Output 'True' } else { Write-Output 'False' }
Why does it output 'True' instead of 'False'?
PowerShell
$a = $true $b = $false if ($a -or $b -and $false) { Write-Output 'True' } else { Write-Output 'False' }
Attempts:
2 left
💡 Hint
Check operator precedence carefully in PowerShell.
✗ Incorrect
In PowerShell, -and has higher precedence than -or, so $b -and $false is evaluated first (False), then $a -or False is True, so it outputs 'True'. A common mistake is evaluating left-to-right ignoring precedence: ($a -or $b) -and $false = True -and False = False.
🚀 Application
expert3:00remaining
Which script correctly filters files modified in the last 7 days and larger than 1MB?
You want to list files in 'C:\Logs' that were modified in the last 7 days AND are larger than 1MB. Which script correctly uses logical operators to do this?
Attempts:
2 left
💡 Hint
Check the logical operators and syntax carefully.
✗ Incorrect
Option C correctly uses -ge to check files modified on or after 7 days ago (i.e., last 7 days) AND -and for size > 1MB (1MB is valid: 1048576 bytes). Option C uses equivalent logic with -not (... -lt ...) but is more complex. Option C uses -or (wrong logic). Option C uses invalid '-and-or'.