Complete the code to return the sum of two numbers.
function Add-Numbers {
param($a, $b)
return $a [1] $b
}
Add-Numbers 3 4The return statement returns the sum of $a and $b using the + operator.
Complete the code to return the length of a string.
function Get-Length {
param($text)
return $text.[1]
}
Get-Length 'hello'Length() as a method instead of a property.Count which is for collections, not strings.The Length property returns the number of characters in the string.
Fix the error in the function to correctly return the square of a number.
function Get-Square {
param($num)
return $num [1] 2
}
Get-Square 5^ which is bitwise XOR in PowerShell.* which is not exponentiation.PowerShell uses ** for exponentiation to return the square of a number.
Fill both blanks to return only even numbers from a list.
$numbers = 1..10 function Get-Evens { param($nums) return $nums | Where-Object { $_ [1] 2 [2] 0 } } Get-Evens $numbers
== which is not the equality operator in PowerShell.!= which means not equal.The modulo operator % finds the remainder. -eq checks if remainder equals zero, meaning the number is even.
Fill all three blanks to return a dictionary of words and their lengths for words longer than 3 characters.
$words = @('cat', 'house', 'dog', 'elephant') $result = @{} foreach ($word in $words) { if ($word.[1] [2] 3) { $result[$word] = $word.[3] } } $result
-le or -lt which mean less or less equal.Length gets the word length. -gt means greater than, so words longer than 3 are included.
