Challenge - 5 Problems
PowerShell Range 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 range operator?
Consider the following PowerShell command:
What will be the output?
$result = 5..8
$result
What will be the output?
PowerShell
$result = 5..8
$resultAttempts:
2 left
💡 Hint
The range operator creates a sequence of numbers from the first to the second number.
✗ Incorrect
The range operator (..) in PowerShell generates an array of integers starting from the left number up to the right number inclusive. So 5..8 produces 5, 6, 7, 8.
💻 Command Output
intermediate2:00remaining
What does this PowerShell code output?
Look at this code snippet:
What will be the output?
$numbers = 10..7
$numbers
What will be the output?
PowerShell
$numbers = 10..7
$numbersAttempts:
2 left
💡 Hint
The range operator counts down if the first number is greater than the second.
✗ Incorrect
PowerShell's range operator creates an ascending sequence only if the first number is less than or equal to the second. If the first number is greater, it produces an empty array. So 10..7 produces an empty array.
📝 Syntax
advanced2:00remaining
Which option correctly uses the range operator to create an array from 3 to 6?
Select the PowerShell code that correctly creates an array containing numbers 3, 4, 5, and 6.
Attempts:
2 left
💡 Hint
The range operator uses two dots between numbers.
✗ Incorrect
The correct syntax for the range operator is two dots (..). Option B uses this correctly. Option B has three dots which is invalid syntax. Option B uses a dash which is subtraction, not range. Option B uses extra dots which is invalid.
🚀 Application
advanced2:00remaining
How many elements are in the array created by this range?
Given this PowerShell code:
How many elements does $array contain?
$array = 15..10
How many elements does $array contain?
Attempts:
2 left
💡 Hint
Count all numbers from 15 down to 10 inclusive.
✗ Incorrect
PowerShell's range operator only creates ascending sequences. Since 15 is greater than 10, the range 15..10 produces an empty array with 0 elements.
🧠 Conceptual
expert2:00remaining
What error does this PowerShell code produce?
Analyze this code:
What happens when you run it?
$result = 5..'8'
What happens when you run it?
Attempts:
2 left
💡 Hint
The range operator requires both ends to be integers.
✗ Incorrect
PowerShell cannot create a range when one end is a string that cannot be converted to an integer automatically. This causes a conversion error.