Bird
0
0

Identify the error in this PowerShell switch statement:

medium📝 Debug Q14 of 15
PowerShell - Control Flow
Identify the error in this PowerShell switch statement:
switch $color {
  'red' { 'Stop' }
  'green' { 'Go' }
  default { 'Wait' }
}
AMissing quotes around case values
BMissing parentheses around $color
CMissing default case
DIncorrect use of curly braces
Step-by-Step Solution
Solution:
  1. Step 1: Check switch syntax

    PowerShell requires parentheses around the variable in switch: switch ($color) { ... }
  2. Step 2: Verify other parts

    Quotes around case values and default case are correct; curly braces are used properly.
  3. Final Answer:

    Missing parentheses around $color -> Option B
  4. Quick Check:

    Parentheses required around variable = A [OK]
Quick Trick: Always wrap the switch variable in parentheses [OK]
Common Mistakes:
  • Omitting parentheses around the switch variable
  • Thinking quotes are optional for strings
  • Confusing default case necessity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes