Bird
0
0

Find the error in this PowerShell snippet:

medium📝 Debug Q7 of 15
PowerShell - Operators
Find the error in this PowerShell snippet:
$a = 5
$a -=
3
Write-Output $a
AThere is no error; code runs fine
BThe subtraction assignment operator is split incorrectly across lines
CWrite-Output requires a semicolon
DVariable $a is not assigned a value
Step-by-Step Solution
Solution:
  1. Step 1: Analyze operator usage

    The operator -= must be on the same line as the variable and value; splitting it causes syntax error.
  2. Step 2: Confirm other syntax parts

    $a is assigned 5, Write-Output works without semicolon, so no error there.
  3. Final Answer:

    The subtraction assignment operator is split incorrectly across lines -> Option B
  4. Quick Check:

    Keep assignment operators and values on the same line [OK]
Quick Trick: Keep operator and value on same line [OK]
Common Mistakes:
  • Splitting operator and value across lines
  • Adding unnecessary semicolons
  • Misunderstanding Write-Output syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes