0
0
PowerShellscripting~10 mins

Hash tables (dictionaries) 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 empty hash table in PowerShell.

PowerShell
$hashTable = [1]
Drag options to blanks, or click blank then click option'
A[]
B@{}
C{}
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] which create arrays, not hash tables.
Using just curly braces {} which is not valid for hash tables in PowerShell.
2fill in blank
medium

Complete the code to add a key-value pair 'Name' = 'Alice' to the hash table.

PowerShell
$hashTable = @{}
$hashTable.[1] = 'Alice'
Drag options to blanks, or click blank then click option'
AKey
BAdd
CName
DValue
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use 'Add' as a property name instead of the key.
Using 'Key' or 'Value' which are not valid property names.
3fill in blank
hard

Fix the error in the code to retrieve the value for key 'Age' from the hash table.

PowerShell
$age = $hashTable[1]'Age'
Drag options to blanks, or click blank then click option'
A['Age']
B.Age
C('Age')
D[Age]
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation with quotes which causes errors.
Using parentheses which is invalid syntax here.
4fill in blank
hard

Fill both blanks to create a hash table with keys 'City' and 'Country' and values 'Paris' and 'France'.

PowerShell
$location = @[1] = '[2]'}
Drag options to blanks, or click blank then click option'
A'City'
B'Country'
CParis
DFrance
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the key string.
Using commas instead of '=' to separate key and value.
5fill in blank
hard

Fill all three blanks to create a hash table with keys 'Fruit' and 'Color' and values 'Apple' and 'Red'.

PowerShell
$fruitInfo = @[1] = '[2]'; [3] = 'Red'}
Drag options to blanks, or click blank then click option'
A'Fruit'
BApple
C'Color'
D'Red'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of semicolons to separate pairs.
Not quoting the keys.