Challenge - 5 Problems
PowerShell String Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell code with string interpolation?
Consider the following PowerShell script. What will it output?
PowerShell
$name = "Alice" $age = 30 Write-Output "My name is $name and I am $age years old."
Attempts:
2 left
💡 Hint
In PowerShell, variables inside double quotes are replaced by their values.
✗ Incorrect
PowerShell replaces variables inside double quotes with their values, so $name and $age are replaced by 'Alice' and '30' respectively.
💻 Command Output
intermediate2:00remaining
What does this PowerShell code output when using nested expressions in double quotes?
Look at this script and choose the correct output:
PowerShell
$count = 5 Write-Output "There are $($count + 3) items."
Attempts:
2 left
💡 Hint
The $() syntax evaluates the expression inside the parentheses.
✗ Incorrect
The expression $($count + 3) calculates 5 + 3 = 8, so the output is 'There are 8 items.'
💻 Command Output
advanced2:00remaining
What is the output of this PowerShell string interpolation with a file path?
What will this script output?
PowerShell
$path = "C:\Program Files\App" Write-Output "The path is: $path"
Attempts:
2 left
💡 Hint
Backslashes are literal characters in PowerShell double-quoted strings.
✗ Incorrect
PowerShell interpolates $path, and backslashes are literal in double-quoted strings, so the path outputs with single backslashes.
🚀 Application
advanced2:00remaining
How many items are in the array after this PowerShell script runs?
Given this script, how many items does $results contain?
PowerShell
$results = @() for ($i = 1; $i -le 3; $i++) { $results += "Item $i" } $results
Attempts:
2 left
💡 Hint
Each loop adds one string to the array.
✗ Incorrect
The loop runs 3 times, each time adding one item, so $results has 3 items.
🧠 Conceptual
expert2:00remaining
What error does this PowerShell script raise?
What error will this script produce when run?
PowerShell
$value = 10 Write-Output "Result: $value + 5"
Attempts:
2 left
💡 Hint
Check how PowerShell treats expressions inside double quotes without $()
✗ Incorrect
PowerShell does not evaluate '+ 5' as an expression inside double quotes unless wrapped in $(), so it outputs the string literally.