Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the string '123' to an integer.
PowerShell
$number = [[1]]'123'
Drag options to blanks, or click blank then click option'
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.
✗ Incorrect
In PowerShell, [int] casts a value to an integer type.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Casting to [int] does not change the value.
Casting to [string] converts the number to text.
✗ Incorrect
Casting 0 to [bool] results in False, as 0 is considered false in boolean context.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [int] causes an error because 'True' is not a number.
Using [string] keeps the value as text.
✗ Incorrect
Casting the string 'True' to [bool] converts it to the boolean value True.
4fill in blank
hardFill 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'
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.
✗ Incorrect
First cast the string to [double] to get the decimal number, then cast to [int] to get the integer part.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $w as key keeps keys lowercase.
Filtering with incorrect condition includes unwanted words.
✗ Incorrect
The keys are uppercase words, values are their lengths, filtered to lengths greater than 3.