Challenge - 5 Problems
PowerShell Arrays 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 array operation?
Consider the following PowerShell code snippet. What will be the output after running it?
PowerShell
$arr = 1,2,3,4,5 $arr[1..3]
Attempts:
2 left
💡 Hint
Remember that array slicing with [start..end] includes both start and end indices.
✗ Incorrect
The slice $arr[1..3] selects elements at indices 1, 2, and 3, which are 2, 3, and 4 respectively.
📝 Syntax
intermediate2:00remaining
Which option correctly creates an array of strings in PowerShell?
Select the option that correctly creates an array containing the strings "apple", "banana", and "cherry".
Attempts:
2 left
💡 Hint
PowerShell uses @() to create arrays.
✗ Incorrect
Option C uses the correct syntax @() to create an array. Options B, C, and D are invalid in PowerShell for array creation.
🔧 Debug
advanced2:00remaining
Why does this PowerShell array code produce an error?
The following code is intended to add an element to an existing array, but it causes an error. What is the reason?
PowerShell
$arr = 1,2,3 $arr += 4 $arr[3]
Attempts:
2 left
💡 Hint
Try running the code in PowerShell to see the actual behavior.
✗ Incorrect
In PowerShell, += on arrays creates a new array with the added element. So $arr becomes 1,2,3,4 and $arr[3] is 4.
🚀 Application
advanced2:00remaining
How to filter an array to only even numbers in PowerShell?
Given an array $numbers = 1..10, which option correctly filters it to only even numbers?
PowerShell
$numbers = 1..10Attempts:
2 left
💡 Hint
Use the correct cmdlet for filtering in PowerShell pipelines.
✗ Incorrect
Where-Object is the correct cmdlet to filter elements in a pipeline. Options A, B, and D are invalid or incorrect usage.
🧠 Conceptual
expert3:00remaining
What is the length of the array after this PowerShell operation?
Given the code below, what is the length of $arr after execution?
PowerShell
$arr = 1,2,3 $arr = $arr + @(4,5) $arr = $arr[1..3]
Attempts:
2 left
💡 Hint
Track the array length after each operation carefully.
✗ Incorrect
Initially $arr has 3 elements. After adding @(4,5), it has 5 elements. Then slicing [1..3] selects 3 elements, so length is 3.