0
0
PowerShellscripting~10 mins

Why operators perform comparisons and logic in PowerShell - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the number is equal to 10.

PowerShell
if ($number [1] 10) { Write-Output "Equal" }
Drag options to blanks, or click blank then click option'
A-gt
B-eq
C-lt
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -ne instead of -eq
Using -lt or -gt which check less or greater than
2fill in blank
medium

Complete the code to check if the value is less than 5.

PowerShell
if ($value [1] 5) { Write-Output "Less than 5" }
Drag options to blanks, or click blank then click option'
A-eq
B-ge
C-lt
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -ge which means greater or equal
Using -eq which means equal
3fill in blank
hard

Fix the error in the code to check if $a is not equal to $b.

PowerShell
if ($a [1] $b) { Write-Output "Not equal" }
Drag options to blanks, or click blank then click option'
A-eq
B-gt
C-lt
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -eq which means equal
Using -lt or -gt which check less or greater than
4fill in blank
hard

Fill both blanks to check if $x is greater than 5 and less than 10.

PowerShell
if (($x [1] 5) -and ($x [2] 10)) { Write-Output "Between 5 and 10" }
Drag options to blanks, or click blank then click option'
A-gt
B-lt
C-eq
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using -eq or -ne instead of comparison operators
Mixing up greater and less than
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as uppercase words and values as their lengths if length is greater than 3.

PowerShell
$result = @{}; foreach ($word in $words) { if (([1] = $word.ToUpper()) -and ($word.Length [2] 3)) { $result[[3]] = $word.Length } }
Drag options to blanks, or click blank then click option'
A$key
B-gt
C$word
D$word.ToUpper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using $word instead of uppercase for key
Using -lt instead of -gt
Using $word instead of $key as dictionary key