0
0
PowerShellscripting~10 mins

String type and interpolation in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a double-quoted string that supports variable interpolation.

PowerShell
$name = 'Alice'
$message = [1]"Hello, $name!"
Drag options to blanks, or click blank then click option'
A"
B$
C'
D`
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which do not interpolate variables.
Using backticks which are escape characters, not string delimiters.
2fill in blank
medium

Complete the code to create a here-string that preserves line breaks.

PowerShell
$text = @[1]
This is line one.
This is line two.
@
Drag options to blanks, or click blank then click option'
A"""
B@"
C@'
D"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes @' which create literal strings without variable interpolation.
Using triple quotes which are not valid in PowerShell.
3fill in blank
hard

Fix the error in the string interpolation to correctly include the variable value.

PowerShell
$count = 5
Write-Output "You have [1] items."
Drag options to blanks, or click blank then click option'
A'$count'
B$count
C${count}
D`$count
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which prevent interpolation.
Using backtick which escapes the dollar sign instead of interpolating.
4fill in blank
hard

Fill both blanks to create a string that includes a variable and a calculated expression.

PowerShell
$price = 10
$quantity = 3
$total = [1]"Total cost: $[2]"
Drag options to blanks, or click blank then click option'
A"
Bprice * quantity
Cprice + quantity
D'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which prevent interpolation.
Using addition instead of multiplication for total cost.
5fill in blank
hard

Fill all three blanks to create a here-string with variable interpolation and a newline.

PowerShell
$user = 'Bob'
$message = @[1]
Hello, $[2]!
Welcome to the system.
[3]
Drag options to blanks, or click blank then click option'
A"
Buser
C"@
D'@
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes '@ which create literal strings without interpolation.
Forgetting to close the here-string properly.