Challenge - 5 Problems
PowerShell Variable 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?
Consider the following script:
$name = "Alice" Write-Output $nameWhat will be printed when this script runs?
PowerShell
$name = "Alice"
Write-Output $nameAttempts:
2 left
💡 Hint
Variables in PowerShell start with $. The Write-Output command prints the value of the variable.
✗ Incorrect
The variable $name holds the string "Alice". Write-Output prints the value stored in $name, so it outputs Alice.
📝 Syntax
intermediate2:00remaining
Which option correctly creates a variable with the value 10?
In PowerShell, you want to create a variable named $count with the number 10. Which line is correct?
Attempts:
2 left
💡 Hint
PowerShell uses = to assign values to variables starting with $.
✗ Incorrect
In PowerShell, variables start with $ and assignment uses =. So $count = 10 is correct.
🔧 Debug
advanced2:00remaining
What error does this code produce?
Look at this script:
name = "Bob" Write-Output $nameWhat error will occur when running it?
PowerShell
name = "Bob"
Write-Output $nameAttempts:
2 left
💡 Hint
In PowerShell, variables must start with $.
✗ Incorrect
The variable 'name' is assigned without $, so PowerShell treats it as a command or string, causing an error when $name is used.
🚀 Application
advanced2:00remaining
How many variables are created after running this script?
Consider this script:
$a = 5 $b = $a $c = $b + 10How many variables exist after running it?
PowerShell
$a = 5 $b = $a $c = $b + 10
Attempts:
2 left
💡 Hint
Each line creates or assigns a variable starting with $.
✗ Incorrect
Variables $a, $b, and $c are all created and assigned values, so there are 3 variables.
🧠 Conceptual
expert2:00remaining
Which option best describes variable naming rules in PowerShell?
Choose the correct statement about variable names in PowerShell.
Attempts:
2 left
💡 Hint
Remember that $ is part of the variable name syntax in PowerShell.
✗ Incorrect
In PowerShell, variables start with $, can include letters, numbers, and underscores, and are case-insensitive.