0
0
PowerShellscripting~10 mins

Integer and floating-point types 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 declare an integer variable with value 10.

PowerShell
$number = [1]
Drag options to blanks, or click blank then click option'
A'10'
B10
C10.0
D$null
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number makes it a string, not an integer.
Using a decimal point makes it a floating-point number.
2fill in blank
medium

Complete the code to declare a floating-point variable with value 3.14.

PowerShell
$pi = [1]
Drag options to blanks, or click blank then click option'
A314
B3
C'3.14'
D3.14
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes turns the number into a string.
Using an integer value instead of a floating-point.
3fill in blank
hard

Fix the error in the code to correctly convert a string to an integer.

PowerShell
$num = [int][1]
Drag options to blanks, or click blank then click option'
A25.0
B25
C'25'
D"25"
Attempts:
3 left
💡 Hint
Common Mistakes
Casting a number instead of a string.
Using double quotes incorrectly.
4fill in blank
hard

Fill both blanks to declare a floating-point variable and display its type.

PowerShell
$value = [1]
$type = $value.GetType().[2]
Drag options to blanks, or click blank then click option'
A5.5
BName
CFullName
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer instead of a floating-point number.
Using 'FullName' which gives the full type name, not just the simple name.
5fill in blank
hard

Fill all three blanks to create a hashtable with integer keys and floating-point values (some greater than 2.5).

PowerShell
$data = @{1 = [1]; 2 = [2]; 3 = [3]
$result = @{}
foreach ($key in $data.Keys) {
  if ($data[$key] -gt 2.5) {
    $result[$key] = $data[$key]
  }
}
$result
Drag options to blanks, or click blank then click option'
A1.5
B3.0
C4.5
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using integers instead of floating-point numbers.
Using only values less than or equal to 2.5 which will all be filtered out.