Bird
0
0

Identify the error in this script:

medium📝 Debug Q6 of 15
PowerShell - Scripting Best Practices
Identify the error in this script:
$num = 5
if $num -gt 3 {
  Write-Output 'Greater than 3'
}
AIncorrect variable name
BMissing parentheses around the if condition
CWrite-Output is misspelled
DNo error
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

    PowerShell requires parentheses around conditions in if statements.
  2. Step 2: Identify missing parentheses

    The condition is not enclosed in parentheses, causing a syntax error.
  3. Final Answer:

    Missing parentheses around the if condition -> Option B
  4. Quick Check:

    If condition needs parentheses = A [OK]
Quick Trick: Always use parentheses around if conditions [OK]
Common Mistakes:
  • Forgetting parentheses in if statements
  • Assuming variable name errors
  • Thinking Write-Output is misspelled

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes