0
0
PowerShellscripting~20 mins

Range operator (..) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Range 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 range operator?
Consider the following PowerShell command:
$result = 5..8
$result

What will be the output?
PowerShell
$result = 5..8
$result
A5 6 7 8
B5..8
C8 7 6 5
DError: Invalid range operator usage
Attempts:
2 left
💡 Hint
The range operator creates a sequence of numbers from the first to the second number.
💻 Command Output
intermediate
2:00remaining
What does this PowerShell code output?
Look at this code snippet:
$numbers = 10..7
$numbers

What will be the output?
PowerShell
$numbers = 10..7
$numbers
A10 9 8 7
B7 8 9 10
C10 7
DEmpty array
Attempts:
2 left
💡 Hint
The range operator counts down if the first number is greater than the second.
📝 Syntax
advanced
2: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.
A$arr = 3..6..1
B$arr = 3..6
C$arr = 3-6
D$arr = 3...6
Attempts:
2 left
💡 Hint
The range operator uses two dots between numbers.
🚀 Application
advanced
2:00remaining
How many elements are in the array created by this range?
Given this PowerShell code:
$array = 15..10

How many elements does $array contain?
A4
B5
C0
D6
Attempts:
2 left
💡 Hint
Count all numbers from 15 down to 10 inclusive.
🧠 Conceptual
expert
2:00remaining
What error does this PowerShell code produce?
Analyze this code:
$result = 5..'8'

What happens when you run it?
AError: Cannot convert value '8' to type 'System.Int32'
BOutputs: 5 '8'
COutputs: 5 6 7 8
DEmpty array
Attempts:
2 left
💡 Hint
The range operator requires both ends to be integers.