Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is positive.
PowerShell
if ($number [1] 0) { Write-Output "Positive" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' which means less than, so it would check for negative numbers.
Using '-eq' which checks for equality, not greater than.
✗ Incorrect
The operator '-gt' means 'greater than', so it checks if $number is greater than 0.
2fill in blank
mediumComplete the code to check if a number is zero.
PowerShell
if ($number -gt 0) { Write-Output "Positive" } elseif ($number [1] 0) { Write-Output "Zero" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' or '-ge' which check less than or greater or equal, not equality.
Using '-ne' which means not equal, the opposite of what is needed.
✗ Incorrect
The operator '-eq' means 'equals', so it checks if $number is exactly zero.
3fill in blank
hardFix the error in the else statement syntax.
PowerShell
if ($score -ge 90) { Write-Output "A" } elseif ($score -ge 80) { Write-Output "B" } else[1]Write-Output "F" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'then' after else, which is not valid in PowerShell.
Writing 'elseif' instead of 'else' for the final block.
✗ Incorrect
In PowerShell, 'else' must be followed by a space and then a block starting with '{'. No extra keywords like 'then' are used.
4fill in blank
hardFill both blanks to complete the if-elseif structure checking temperature.
PowerShell
if ($temp [1] 30) { Write-Output "Hot" } elseif ($temp [2] 15) { Write-Output "Warm" } else { Write-Output "Cold" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ge' or '-le' which include equality and may change logic.
Swapping the operators and confusing hot and warm conditions.
✗ Incorrect
The first condition checks if temperature is greater than 30 (hot). The second checks if temperature is less than 15 (cold). Otherwise, it's warm.
5fill in blank
hardFill all three blanks to create a dictionary with keys as uppercase words and values as their lengths if length is greater than 3.
PowerShell
foreach ($word in $words) { if (($word.Length [1] 3) [2] $true)) { $dict[[3]] = $word.Length } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' instead of '-gt' which reverses the condition.
Using '-or' instead of '-and' which changes logic.
Not converting the word to uppercase for the dictionary key.
✗ Incorrect
The condition checks if word length is greater than 3 and uses '-and' to combine conditions if needed. The dictionary key is the uppercase version of the word.