Bird
0
0

Identify the error in this PowerShell script:

medium📝 Debug Q14 of 15
PowerShell - Operators
Identify the error in this PowerShell script:
$x = 8
$y = 2
$z = $x % $y
Write-Output $z
AThere is no error; script runs correctly
BVariables must be declared with types before use
CThe modulus operator (%) is not valid in PowerShell
DWrite-Output cannot print variables
Step-by-Step Solution
Solution:
  1. Step 1: Check validity of modulus operator

    PowerShell supports % as the modulus operator to get remainder.
  2. Step 2: Verify variable usage and output

    Variables can be assigned without explicit types, and Write-Output prints values correctly.
  3. Final Answer:

    There is no error; script runs correctly -> Option A
  4. Quick Check:

    Modulus and Write-Output are valid [OK]
Quick Trick: Modulus (%) works fine; no type declaration needed [OK]
Common Mistakes:
  • Thinking % is invalid operator
  • Believing variables need explicit types
  • Assuming Write-Output can't print variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes