0
0
PowerShellscripting~10 mins

Arrays in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an array with three numbers.

PowerShell
$numbers = @([1])
Drag options to blanks, or click blank then click option'
A1 2 3
B1, 2, 3
C1; 2; 3
D1. 2. 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons instead of commas to separate values.
Using dots instead of commas.
2fill in blank
medium

Complete the code to access the second element of the array.

PowerShell
$secondElement = $numbers[[1]]
Drag options to blanks, or click blank then click option'
A1
B3
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 or 3 as the index for the second element.
Forgetting that indexing starts at zero.
3fill in blank
hard

Fix the error in the code to add an element to the array.

PowerShell
$numbers [1] 4
Drag options to blanks, or click blank then click option'
A*=
B-=
C+
D+=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' which does not modify the original array.
Using '-=' or '*=' which are incorrect here.
4fill in blank
hard

Fill both blanks to create an array of numbers from 4 to 12.

PowerShell
$evens = @((2[1]10)[2]2)
Drag options to blanks, or click blank then click option'
A..
B,
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of the range operator.
Using '-' instead of '+'.
5fill in blank
hard

Fill all three blanks to create a filtered array of numbers greater than 3.

PowerShell
$filtered = $numbers | Where-Object { $_ [1] [2] } | Sort-Object -Descending | Select-Object -First [3]
Drag options to blanks, or click blank then click option'
A-gt
B3
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators like '-lt'.
Selecting wrong number of elements.