Challenge - 5 Problems
PowerShell Number 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 PowerShell script:
$a = 5What will be printed?
$b = 2.5
$c = $a + $b
Write-Output $c.GetType().Name
PowerShell
$a = 5 $b = 2.5 $c = $a + $b Write-Output $c.GetType().Name
Attempts:
2 left
💡 Hint
Adding an integer and a floating-point number results in a floating-point type.
✗ Incorrect
In PowerShell, when you add an integer (Int32) and a floating-point number (Double), the result is promoted to Double to preserve the decimal part.
🧠 Conceptual
intermediate2:00remaining
Which type does PowerShell assign to the number 3.0 by default?
In PowerShell, if you assign the value 3.0 to a variable like this:
$x = 3.0What is the default type of $x?
Attempts:
2 left
💡 Hint
Numbers with decimal points default to a floating-point type.
✗ Incorrect
PowerShell treats numbers with decimal points as Double by default, which is a 64-bit floating-point type.
📝 Syntax
advanced2:00remaining
Which PowerShell assignment causes a type conversion error?
Which of the following assignments will cause a runtime error in PowerShell due to type mismatch?
Attempts:
2 left
💡 Hint
Converting a non-numeric string to int causes an error.
✗ Incorrect
Casting the string 'abc' to an integer fails because 'abc' is not a valid number.
🚀 Application
advanced2:00remaining
How many items are in the resulting array after this PowerShell script?
What is the length of the array $arr after running this script?
$arr = @()
for ($i = 0; $i -lt 5; $i++) {
if ($i -is [int]) { $arr += $i }
else { $arr += [math]::Round($i) }
}
Attempts:
2 left
💡 Hint
The loop runs 5 times and adds one item each time.
✗ Incorrect
The loop runs from 0 to 4 (5 times). Each time, $i is an integer, so the if condition is true and $i is added to $arr. So $arr has 5 items.
🔧 Debug
expert2:00remaining
What error does this PowerShell code raise?
Examine this code snippet:
What error will occur when running this code?
$num = 1.5
$intNum = [int]$num
$result = $intNum / 0
What error will occur when running this code?
Attempts:
2 left
💡 Hint
Dividing by zero causes an error in integer division.
✗ Incorrect
Casting 1.5 to int results in 1. Dividing 1 by 0 causes a DivideByZeroException in PowerShell.