0
0
PowerShellscripting~20 mins

Arithmetic operators in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Arithmetic Master
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 arithmetic operation?
Consider the following PowerShell command:
$result = 5 + 3 * 2
$result

What is the output?
PowerShell
$result = 5 + 3 * 2
$result
A11
BError
C10
D16
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication happens before addition.
💻 Command Output
intermediate
2:00remaining
What is the output of this division and modulus operation?
Look at this PowerShell code:
$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"
ADivision: 5, Modulus: 1
BDivision: 4.25, Modulus: 1
CDivision: 4, Modulus: 1
DDivision: 4, Modulus: 0
Attempts:
2 left
💡 Hint
Division result is floored to get integer division.
📝 Syntax
advanced
2: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?
A++$count
B$count++
C$count += 1
D$count = $count + 1
Attempts:
2 left
💡 Hint
PowerShell does not support ++ or -- operators.
💻 Command Output
advanced
2:00remaining
What is the output of this PowerShell expression with mixed operators?
Evaluate this PowerShell expression:
$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
A5.66666666666667
B5.66666666666666
C5.6666666666667
D5.66666666666668
Attempts:
2 left
💡 Hint
Division and multiplication have the same precedence and are evaluated left to right.
🔧 Debug
expert
2:00remaining
Why does this PowerShell script produce an error?
This script is intended to calculate the remainder of 15 divided by 4:
$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
AVariables $a and $b are not initialized properly.
B'mod' is not a valid operator in PowerShell; use '%' instead.
CWrite-Output cannot output variables directly.
DPowerShell requires parentheses around arithmetic expressions.
Attempts:
2 left
💡 Hint
Check the operator used for modulus in PowerShell.