Challenge - 5 Problems
PowerShell Assignment 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 script using assignment operators?
Consider the following script. What will be the value of $a after execution?
PowerShell
$a = 10 $a += 5 $a *= 2 $a -= 4 $a
Attempts:
2 left
💡 Hint
Remember to apply each assignment operator step-by-step.
✗ Incorrect
Start with $a = 10. Then $a += 5 makes $a 15. Next $a *= 2 makes $a 30. Finally $a -= 4 makes $a 26.
💻 Command Output
intermediate2:00remaining
What is the output of this script using string assignment operators?
What will be the value of $str after running this script?
PowerShell
$str = 'Hello' $str += ' World' $str += '!'
Attempts:
2 left
💡 Hint
The += operator appends strings in PowerShell.
✗ Incorrect
The += operator adds the string on the right to the existing string on the left without extra spaces.
📝 Syntax
advanced2:00remaining
Which option will cause a syntax error in PowerShell assignment?
Identify the option that will cause a syntax error when run in PowerShell.
Attempts:
2 left
💡 Hint
Look carefully at the spacing and operator usage.
✗ Incorrect
Option D uses '+ =' which is not a valid assignment operator in PowerShell and causes a syntax error.
🚀 Application
advanced2:00remaining
What is the value of $count after this loop with assignment operators?
Given this script, what is the final value of $count?
PowerShell
$count = 0 for ($i = 1; $i -le 5; $i++) { $count += $i if ($i % 2 -eq 0) { $count -= 1 } } $count
Attempts:
2 left
💡 Hint
Add $i each time, but subtract 1 when $i is even.
✗ Incorrect
Sum 1+2+3+4+5=15. Subtract 1 for i=2 and i=4 (two times), so 15-2=13. But careful: the subtraction happens inside the loop after adding i. The final count is 13.
🧠 Conceptual
expert2:00remaining
Which assignment operator will cause an error when used with a $null variable in PowerShell?
Assuming $var is $null, which assignment operation will cause a runtime error?
PowerShell
$var = $null
# Which operation causes error?
Attempts:
2 left
💡 Hint
Think about how PowerShell treats $null with arithmetic operators.
✗ Incorrect
Dividing by $null causes an error because $null is treated as zero in the denominator, causing division by zero. Adding or subtracting treats $null as zero.