Challenge - 5 Problems
PowerShell Arithmetic 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 arithmetic operation?
Consider the following PowerShell command:
What is the output?
$result = 5 + 3 * 2
$result
What is the output?
PowerShell
$result = 5 + 3 * 2 $result
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication happens before addition.
✗ Incorrect
In PowerShell, multiplication (*) has higher precedence than addition (+). So 3 * 2 = 6, then 5 + 6 = 11.
💻 Command Output
intermediate2:00remaining
What is the output of this division and modulus operation?
Look at this PowerShell code:
What will be printed?
$a = 17
$b = 4
$div = [math]::Floor($a / $b)
$mod = $a % $b
"Division: $div, Modulus: $mod"
What will be printed?
PowerShell
$a = 17 $b = 4 $div = [math]::Floor($a / $b) $mod = $a % $b "Division: $div, Modulus: $mod"
Attempts:
2 left
💡 Hint
Division result is floored to get integer division.
✗ Incorrect
17 divided by 4 is 4.25. Floor rounds down to 4. The modulus operator (%) gives the remainder 1.
📝 Syntax
advanced2:00remaining
Which option correctly increments a variable by 1 in PowerShell?
You want to increase the value of variable $count by 1. Which of these commands will do it correctly?
Attempts:
2 left
💡 Hint
PowerShell does not support ++ or -- operators.
✗ Incorrect
PowerShell does not support the ++ or -- operators. To increment, use '+=' or assign the sum explicitly.
💻 Command Output
advanced2:00remaining
What is the output of this PowerShell expression with mixed operators?
Evaluate this PowerShell expression:
What is the output?
$x = 10
$y = 3
$result = $x / $y * 2 - 1
$result
What is the output?
PowerShell
$x = 10 $y = 3 $result = $x / $y * 2 - 1 $result
Attempts:
2 left
💡 Hint
Division and multiplication have the same precedence and are evaluated left to right.
✗ Incorrect
10 / 3 = 3.33333333333333, times 2 = 6.66666666666666, minus 1 = 5.66666666666667 (rounded).
🔧 Debug
expert2:00remaining
Why does this PowerShell script produce an error?
This script is intended to calculate the remainder of 15 divided by 4:
Why does it fail?
$a = 15
$b = 4
$remainder = $a mod $b
Write-Output $remainder
Why does it fail?
PowerShell
$a = 15 $b = 4 $remainder = $a mod $b Write-Output $remainder
Attempts:
2 left
💡 Hint
Check the operator used for modulus in PowerShell.
✗ Incorrect
PowerShell uses '%' for modulus, not 'mod'. Using 'mod' causes a syntax error.