0
0
PowerShellscripting~10 mins

Comparison operators (-eq, -ne, -gt, -lt) 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 check if variable $a equals 10.

PowerShell
if ($a [1] 10) { Write-Output 'Equal' }
Drag options to blanks, or click blank then click option'
A-gt
B-ne
C-eq
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using -ne instead of -eq causes the condition to be true when values are not equal.
2fill in blank
medium

Complete the code to check if $b is not equal to 5.

PowerShell
if ($b [1] 5) { Write-Output 'Not equal' }
Drag options to blanks, or click blank then click option'
A-eq
B-lt
C-gt
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -eq instead of -ne will give the opposite result.
3fill in blank
hard

Fix the error in the code to check if $num is greater than 100.

PowerShell
if ($num [1] 100) { Write-Output 'Greater' }
Drag options to blanks, or click blank then click option'
A-gt
B-ne
C-eq
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using -lt will check for less than, which is the opposite.
4fill in blank
hard

Fill both blanks to check if $x is less than 50 and not equal to 20.

PowerShell
if (($x [1] 50) -and ($x [2] 20)) { Write-Output 'Valid' }
Drag options to blanks, or click blank then click option'
A-lt
B-eq
C-ne
D-gt
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up -eq and -ne operators.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as $word uppercase, values as $count, filtering counts greater than 10.

PowerShell
$result = @{ [1] = [2] } | Where-Object { $_.Value [3] 10 }
Drag options to blanks, or click blank then click option'
A$word.ToUpper()
B$count
C-gt
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using -lt instead of -gt will filter wrong values.