0
0
PowerShellscripting~20 mins

String type and interpolation in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell String Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell string interpolation?
Consider the following PowerShell code snippet. What will it output?
PowerShell
$name = 'Alice'
$age = 30
"My name is $name and I am $age years old."
AMy name is Alice and I am $age years old.
BMy name is $name and I am $age years old.
CMy name is $name and I am 30 years old.
DMy name is Alice and I am 30 years old.
Attempts:
2 left
💡 Hint
Remember that double quotes allow variable interpolation in PowerShell.
💻 Command Output
intermediate
2:00remaining
What does this PowerShell code output?
What will be the output of this code snippet?
PowerShell
$value = 5
"The value doubled is ${value * 2}."
AThe value doubled is ${value * 2}.
BThe value doubled is 10.
CThe value doubled is 5 * 2.
DThe value doubled is value * 2.
Attempts:
2 left
💡 Hint
Use ${} to evaluate expressions inside strings in PowerShell.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in PowerShell string interpolation?
Identify which of the following lines will cause a syntax error when run in PowerShell.
A"Calculation: $[2 + 3]"
B"Value is ${2 + 3 * 4}"
C"Sum is $(2 + 3) * 4"
D"Result is $((2 + 3) * 4)"
Attempts:
2 left
💡 Hint
PowerShell uses $() or ${} for expressions inside strings, but $[] is invalid.
🚀 Application
advanced
2:00remaining
How to include a literal dollar sign in an interpolated string?
You want to output the string: Price is $5. Which PowerShell code will produce this exact output?
A"Price is $5"
B"Price is $$5"
C"Price is `$5"
D"Price is ${5}"
Attempts:
2 left
💡 Hint
Use the backtick ` to escape special characters in PowerShell strings.
🧠 Conceptual
expert
2:00remaining
What is the type of the variable after this assignment?
In PowerShell, what is the type of the variable $text after this code runs? $text = "Hello, $($env:USERNAME)!"
PowerShell
$text = "Hello, $($env:USERNAME)!"
ASystem.String
BSystem.Object[]
CSystem.Char[]
DSystem.Int32
Attempts:
2 left
💡 Hint
PowerShell variables holding text with interpolation are strings.