Bird
0
0

Find the error in this PowerShell snippet:

medium📝 Debug Q14 of 15
PowerShell - Control Flow
Find the error in this PowerShell snippet:
if $value -gt 10 {
'Greater than 10'
} elseif ($value -eq 10) {
'Equal to 10'
} else {
'Less than 10'
}
ABraces {} are not allowed
BUsing -gt instead of >
CMissing else keyword
DMissing parentheses around first if condition
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax and identify the error

    PowerShell requires parentheses around the condition in if statements. The first if lacks them: "if $value -gt 10 {" should be "if ($value -gt 10) {". Matches "Missing parentheses around first if condition".
  2. Final Answer:

    Missing parentheses around first if condition -> Option D
  3. Quick Check:

    All if conditions need parentheses = A [OK]
Quick Trick: Always put conditions inside parentheses in if [OK]
Common Mistakes:
  • Omitting parentheses in if
  • Confusing -gt with > (both valid but -gt preferred)
  • Forgetting else keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes