Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a switch statement for the variable $color.
PowerShell
switch ([1]) { 'red' { Write-Output 'Stop' } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist like $value or $item.
Forgetting the $ sign before the variable name.
✗ Incorrect
The switch statement must use the variable $color to check its value.
2fill in blank
mediumComplete the code to output 'Go' when $color is green.
PowerShell
switch ($color) { 'green' { [1] 'Go' } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Print which is not a PowerShell command.
Using Echo which is an alias but less clear.
✗ Incorrect
Write-Output is the standard way to output text in PowerShell scripts.
3fill in blank
hardFix the error in the switch statement to correctly handle multiple values.
PowerShell
switch ($day) { [1] { Write-Output 'Weekend' } default { Write-Output 'Weekday' } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces or semicolons instead of commas to separate values.
Using the pipe character which is not valid here.
✗ Incorrect
Multiple values in a switch case are separated by commas in PowerShell.
4fill in blank
hardFill both blanks to complete the switch that outputs messages for fruit colors.
PowerShell
switch ($fruit) { [1] { Write-Output 'Yellow fruit' } [2] { Write-Output 'Red fruit' } } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing fruit names with wrong colors.
Using fruits not listed in options.
✗ Incorrect
The switch cases check for 'lemon' to output 'Yellow fruit' and 'cherry' for 'Red fruit'.
5fill in blank
hardFill all three blanks to create a switch that outputs messages for traffic light colors.
PowerShell
switch ([1]) { [2] { Write-Output 'Stop' } [3] { Write-Output 'Go' } default { Write-Output 'Caution' } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable name.
Mixing up color cases.
✗ Incorrect
The switch uses $light variable; 'red' outputs 'Stop', 'green' outputs 'Go', others output 'Caution'.