0
0
PowerShellscripting~10 mins

Logical operators (-and, -or, -not) in PowerShell - Interactive Code Practice

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

Complete the code to check if both conditions are true using the correct logical operator.

PowerShell
if ($a -gt 5 [1] $b -lt 10) { Write-Output "Both true" }
Drag options to blanks, or click blank then click option'
A-and
B-or
C-not
D-xor
Attempts:
3 left
💡 Hint
Common Mistakes
Using -or instead of -and causes the condition to be true if either is true.
Using -not negates a single condition, not both.
2fill in blank
medium

Complete the code to check if either condition is true using the correct logical operator.

PowerShell
if ($x -eq 0 [1] $y -eq 1) { Write-Output "At least one is true" }
Drag options to blanks, or click blank then click option'
A-and
B-xor
C-not
D-or
Attempts:
3 left
💡 Hint
Common Mistakes
Using -and requires both conditions to be true, which is not what we want here.
Using -not negates a condition, not combines two.
3fill in blank
hard

Fix the error in the code by choosing the correct logical operator to negate the condition.

PowerShell
if ([1] ($status -eq 'Success')) { Write-Output "Not successful" }
Drag options to blanks, or click blank then click option'
A-or
B-not
C-and
D-xor
Attempts:
3 left
💡 Hint
Common Mistakes
Using -and or -or here causes syntax errors or wrong logic.
For negation, only -not works correctly.
4fill in blank
hard

Fill both blanks to create a condition that is true when $a is greater than 10 and $b is not equal to 5.

PowerShell
if ($a [1] 10 [2] $b -ne 5) { Write-Output "Condition met" }
Drag options to blanks, or click blank then click option'
A-gt
B-lt
C-and
D-or
Attempts:
3 left
💡 Hint
Common Mistakes
Using -lt instead of -gt reverses the comparison.
Using -or allows the condition to be true if only one side is true.
5fill in blank
hard

Fill all three blanks to create a condition that is true when $x is less than 5 or $y is not equal to 10, but not when $z is true.

PowerShell
if (($x [1] 5 [2] $y -ne 10) -and [3] $z) { Write-Output "Complex condition met" }
Drag options to blanks, or click blank then click option'
A-lt
B-or
C-and
D-not
Attempts:
3 left
💡 Hint
Common Mistakes
Using -and instead of -or changes the logic.
Not negating $z causes the condition to behave incorrectly.