Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function named 'Greet' that prints a message.
PowerShell
function [1] { Write-Output "Hello, friend!" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'Greet'.
Forgetting to write 'function' keyword.
✗ Incorrect
The function name should be 'Greet' to match the task requirement.
2fill in blank
mediumComplete the code to call the function named 'Greet'.
PowerShell
[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call the function with 'function' keyword.
Using Write-Output instead of calling the function.
✗ Incorrect
To call a function in PowerShell, just write its name.
3fill in blank
hardFix the error in the function definition by completing the blank.
PowerShell
function Greet {
[1] "Hello from function!"
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Print' or 'Say' which are not PowerShell commands.
Using 'echo' which works in some shells but not recommended here.
✗ Incorrect
In PowerShell, 'Write-Output' sends output to the console.
4fill in blank
hardComplete the code to create a function 'Add' that takes two numbers and returns their sum.
PowerShell
function Add($a, $b) {
return $a [1] $b
}
$result = Add 5,3
Write-Output $result Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+'.
Not separating arguments with a comma.
✗ Incorrect
Use '+' to add numbers and ',' to separate arguments when calling the function.
5fill in blank
hardFill all three blanks to define a function 'IsEven' that returns true if a number is even.
PowerShell
function IsEven($num) {
if ($num [1] 2 [2] 0) {
return [3]
} else {
return $false
}
}
Write-Output (IsEven 4) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '-eq' for equality.
Returning 'true' instead of '$true'.
✗ Incorrect
Use '%' for modulo, '-eq' for equality check, and '$true' to return true.