0
0
PowerShellscripting~20 mins

Why variables store data in PowerShell - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variable Mastery Badge
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 script?
Look at the script below. What will be printed when it runs?
PowerShell
$name = "Alice"
Write-Output $name
AAlice
B$name
CError: Variable not defined
DWrite-Output $name
Attempts:
2 left
💡 Hint
Variables hold values. When you output a variable, you see its stored value.
🧠 Conceptual
intermediate
2:00remaining
Why do variables store data in scripts?
Choose the best reason why variables are used to store data in scripts.
ATo keep information that can be used later in the script
BTo make the script run faster by skipping commands
CTo display messages on the screen automatically
DTo prevent the script from running more than once
Attempts:
2 left
💡 Hint
Think about how you remember things to use later.
🔧 Debug
advanced
2:00remaining
What does this script output?
This script tries to print a variable before assigning it. What will it show?
PowerShell
Write-Output $username
$username = "Bob"
ABob
BEmpty output
CSyntaxError: Unexpected token
DError: Variable $username is not defined
Attempts:
2 left
💡 Hint
Undefined variables output nothing in PowerShell.
🚀 Application
advanced
2:00remaining
What is the value of $count after running this script?
Look at the script. What number will $count hold at the end?
PowerShell
$count = 0
$count = $count + 1
$count = $count + 2
A0
B1
CError: Cannot add to variable
D3
Attempts:
2 left
💡 Hint
Add each number step by step to the starting value.
📝 Syntax
expert
2:00remaining
Which option correctly stores and outputs a string variable?
Choose the script that correctly stores the word "Hello" in a variable and prints it.
A
$greeting = Hello
Write-Output $greeting
B
$greeting = 'Hello'
Write-Output $greeting
C
$greeting = "Hello"
Write-Output $greeting
D
$greeting = "Hello"
Write-Output greeting
Attempts:
2 left
💡 Hint
Strings must be inside quotes in PowerShell.