Challenge - 5 Problems
Boolean Mastery in PowerShell
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 code?
Consider the following PowerShell script:
What will be printed?
$a = $true
$b = $false
$result = $a -and $b
Write-Output $result
What will be printed?
PowerShell
$a = $true $b = $false $result = $a -and $b Write-Output $result
Attempts:
2 left
💡 Hint
Remember that -and returns True only if both sides are True.
✗ Incorrect
The -and operator returns True only if both operands are True. Here, $a is True but $b is False, so the result is False.
💻 Command Output
intermediate2:00remaining
What does this PowerShell expression output?
What is the output of this code?
Write-Output ($false -or $true)
PowerShell
Write-Output ($false -or $true)
Attempts:
2 left
💡 Hint
The -or operator returns True if at least one operand is True.
✗ Incorrect
Since one operand is True, the -or operator returns True.
📝 Syntax
advanced2:00remaining
Which option correctly assigns a Boolean value in PowerShell?
Which of the following lines correctly assigns a Boolean True value to the variable $flag?
Attempts:
2 left
💡 Hint
PowerShell Boolean constants start with a dollar sign and capital T.
✗ Incorrect
In PowerShell, Boolean constants are case-insensitive but must be prefixed with a dollar sign, like $True or $False. 'True' without $ is treated as a string or variable name.
🚀 Application
advanced2:00remaining
What is the output of this conditional check?
Given this script:
What will it print?
$value = 0
if ($value) { Write-Output 'Yes' } else { Write-Output 'No' }
What will it print?
PowerShell
$value = 0 if ($value) { Write-Output 'Yes' } else { Write-Output 'No' }
Attempts:
2 left
💡 Hint
In PowerShell, non-null values are treated as True in conditionals.
✗ Incorrect
In PowerShell, the integer 0 is treated as False in conditionals, so the else block runs and prints 'No'.
🧠 Conceptual
expert2:00remaining
What error does this PowerShell script raise?
What error will this script produce?
$x = 'True'
if ($x -eq $True) { Write-Output 'Match' } else { Write-Output 'No Match' }
PowerShell
$x = 'True' if ($x -eq $True) { Write-Output 'Match' } else { Write-Output 'No Match' }
Attempts:
2 left
💡 Hint
Check how PowerShell compares strings and Booleans.
✗ Incorrect
PowerShell compares string 'True' to Boolean $True as not equal, so it outputs 'No Match' without error.