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 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."
Attempts:
2 left
💡 Hint
Remember that double quotes allow variable interpolation in PowerShell.
✗ Incorrect
In PowerShell, strings in double quotes expand variables inside them. So $name and $age are replaced by their values.
💻 Command Output
intermediate2: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}."
Attempts:
2 left
💡 Hint
Use ${} to evaluate expressions inside strings in PowerShell.
✗ Incorrect
Using ${} allows PowerShell to evaluate the expression inside and insert the result into the string.
📝 Syntax
advanced2: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.
Attempts:
2 left
💡 Hint
PowerShell uses $() or ${} for expressions inside strings, but $[] is invalid.
✗ Incorrect
The $[] syntax is not valid for string interpolation in PowerShell, causing a syntax error.
🚀 Application
advanced2: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?
Attempts:
2 left
💡 Hint
Use the backtick ` to escape special characters in PowerShell strings.
✗ Incorrect
In PowerShell, the backtick ` escapes the dollar sign to print it literally inside double quotes.
🧠 Conceptual
expert2: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)!"Attempts:
2 left
💡 Hint
PowerShell variables holding text with interpolation are strings.
✗ Incorrect
The variable $text holds a string with interpolated environment variable, so its type is System.String.