0
0
PowerShellscripting~10 mins

Type casting 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 convert the string '123' to an integer.

PowerShell
$number = [[1]]'123'
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cbool
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using [string] instead of [int] will keep the value as text.
Using [bool] will convert to true or false, not a number.
2fill in blank
medium

Complete the code to cast the number 0 to a boolean value.

PowerShell
$flag = [[1]]0
Drag options to blanks, or click blank then click option'
Astring
Bint
Cdouble
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Casting to [int] does not change the value.
Casting to [string] converts the number to text.
3fill in blank
hard

Fix the error in the code to cast the string 'True' to a boolean.

PowerShell
$isActive = [[1]]'True'
Drag options to blanks, or click blank then click option'
Astring
Bint
Cbool
Ddouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using [int] causes an error because 'True' is not a number.
Using [string] keeps the value as text.
4fill in blank
hard

Fill both blanks to cast the string '3.14' to a double and then to an integer.

PowerShell
$piDouble = [[1]]'3.14'
$piInt = [[2]]$piDouble
Drag options to blanks, or click blank then click option'
Adouble
Bint
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Casting directly from string to int loses the decimal part or causes errors.
Casting to [bool] is not appropriate here.
5fill in blank
hard

Fill all three blanks to create a hashtable with keys as uppercase strings and values as integers greater than 3.

PowerShell
$words = @('one', 'two', 'three', 'four')
$result = @{ [1] = [2] for $w in $words if [3] }
Drag options to blanks, or click blank then click option'
A$w.ToUpper()
B$w.Length
C$w.Length -gt 3
D$w
Attempts:
3 left
💡 Hint
Common Mistakes
Using $w as key keeps keys lowercase.
Filtering with incorrect condition includes unwanted words.