Bird
0
0

You want to create a PowerShell function Get-Square that takes a number and returns its square. Which function definition correctly achieves this?

hard📝 Application Q15 of 15
PowerShell - Functions
You want to create a PowerShell function Get-Square that takes a number and returns its square. Which function definition correctly achieves this?
Afunction Get-Square { param($num) return $num * $num }
Bfunction Get-Square($num) { $num ^ 2 }
Cfunction Get-Square { param($num) $num ** 2 }
Dfunction Get-Square { param($num) return $num ^ 2 }
Step-by-Step Solution
Solution:
  1. Step 1: Understand PowerShell multiplication and function syntax

    PowerShell uses * for multiplication; param block defines input parameters.
  2. Step 2: Evaluate each option

    function Get-Square { param($num) return $num * $num } correctly uses param and multiplies $num by itself. function Get-Square($num) { $num ^ 2 } uses valid param syntax but ^ is bitwise XOR, not multiplication. function Get-Square { param($num) $num ** 2 } uses ** which is not PowerShell operator. function Get-Square { param($num) return $num ^ 2 } uses ^ which is bitwise XOR, not power.
  3. Final Answer:

    function Get-Square { param($num) return $num * $num } -> Option A
  4. Quick Check:

    Use * for multiplication, param inside braces [OK]
Quick Trick: Use * for multiplication; param inside braces defines inputs [OK]
Common Mistakes:
  • Using ^ for power instead of multiplication
  • Using ** which is invalid in PowerShell
  • Incorrect param syntax with parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes