Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to match the input using a wildcard pattern in the switch statement.
PowerShell
switch -Wildcard ($input) {
[1] { Write-Output "Matched wildcard pattern" }
default { Write-Output "No match" }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using regex pattern with -Wildcard instead of a wildcard pattern.
Forgetting to put the pattern in quotes.
✗ Incorrect
The -Wildcard parameter expects a wildcard pattern like "hello*" to match strings starting with 'hello'.
2fill in blank
mediumComplete the code to match the input using a regex pattern in the switch statement.
PowerShell
switch -Regex ($input) {
[1] { Write-Output "Matched regex pattern" }
default { Write-Output "No match" }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wildcard pattern with -Regex instead of a regex pattern.
Not anchoring the regex pattern properly.
✗ Incorrect
The -Regex parameter expects a regex pattern like '^hello.*$' to match strings starting with 'hello'.
3fill in blank
hardFix the error in the switch statement to correctly match input ending with 'end' using wildcard.
PowerShell
switch -Wildcard ($input) {
[1] { Write-Output "Ends with 'end'" }
default { Write-Output "No match" }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'end*' which matches strings starting with 'end' instead of ending.
Using '?' which matches exactly one character.
✗ Incorrect
The wildcard '*end' matches any string ending with 'end'.
4fill in blank
hardFill both blanks to match input starting with 'start' using regex and containing digits.
PowerShell
switch -Regex ($input) {
[1] { Write-Output "Starts with start" }
[2] { Write-Output "Contains digits" }
default { Write-Output "No match" }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start$' which matches strings ending with 'start'.
Using '[a-z]+' which matches letters but not digits.
✗ Incorrect
The pattern '^start' matches strings starting with 'start'. The pattern '\d+' matches strings containing one or more digits.
5fill in blank
hardFill all three blanks to create a switch that matches input exactly 'yes', matches input containing 'no' anywhere, and matches input starting with 'maybe' using regex.
PowerShell
switch -Regex ($input) {
[1] { Write-Output "Exact yes" }
[2] { Write-Output "Contains no" }
[3] { Write-Output "Starts with maybe" }
default { Write-Output "No match" }
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'yes' without anchors matches any string containing 'yes', not exactly 'yes'.
Using '^no' which matches strings starting with 'no' only.
✗ Incorrect
The pattern '^yes$' matches exactly 'yes'. The pattern 'no' matches any string containing 'no'. The pattern '^maybe' matches strings starting with 'maybe'.