Bird
0
0

Identify the error in this PowerShell snippet:

medium📝 Debug Q14 of 15
PowerShell - Operators
Identify the error in this PowerShell snippet:
if ($a -eq 5 -or $b = 10) { 'Yes' } else { 'No' }
AUsing = instead of -eq for comparison
BMissing parentheses around conditions
CUsing -or instead of -and
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check comparison operators

    PowerShell uses -eq for equality comparison, not = which is an assignment operator.
  2. Step 2: Identify the error in $b = 10

    $b = 10 assigns 10 to $b, it does not compare. This causes a logic error in the if condition.
  3. Final Answer:

    Using = instead of -eq for comparison -> Option A
  4. Quick Check:

    Comparison needs -eq, not = [OK]
Quick Trick: Use -eq for comparison, = is assignment [OK]
Common Mistakes:
  • Using = instead of -eq in conditions
  • Assuming -or needs parentheses
  • Confusing logical operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes