Exercise 3: A Clean Get-Square Function — Possible Solution ==================================================================== THE FUNCTION ------------------------------ function Get-Square { param( [Parameter(Mandatory)] [int]$n ) $n * $n } WHY THIS AVOIDS POLLUTING THE RETURN VALUE ------------------------------ The function body contains exactly one uncaptured statement - $n * $n - and nothing else. There's no stray Write-Output call, no bare status-message expression, and no other uncaptured line that could join the output the way this chapter's own Get-Doubled example showed happening with its "about to double $n" message. [Parameter(Mandatory)] also ensures the function can't silently run with a missing or wrong-type $n, per this chapter's own parameter material. HOW TO ACTUALLY VERIFY IT RETURNS ONE CLEAN VALUE ------------------------------ Per this chapter's own tip-box, assign the result and check .Count: $result = Get-Square -n 4; $result.Count should report 1, not more. Additionally, $result.GetType().Name can confirm the single value is the expected type (Int32) rather than an array or some other unexpected wrapper - checking .Count is the direct way to catch the "extra uncaptured output" bug this chapter warned about, rather than just assuming the function is clean because it looks simple. WHY THIS WORKS AS AN ANSWER ------------------------------ It provides a correct, working Get-Square function with no extraneous uncaptured output, correctly uses Mandatory to enforce the required parameter, and correctly describes checking .Count (this chapter's own recommended verification habit) rather than just asserting the function is clean without checking.