When I try to enter
function Multiply (x, y) {
return x * y
}
It comes back with the error (when I hover over the x) “Missing ‘)’ function in parameter list”.
And when I hover over the “)” it says "Unexpected token ‘)’ in expression or statement.
Can someone please tell me what’s going on?
Variables in PowerShell begin with a $ character; you’re missing that in both your parameter declaration and the function body.
function Multiply ($x, $y) { return $x * $y }
And as a note, you’re kind of approaching PowerShell with a traditional programming syntax. While it’ll support that, to a degree, just understand that keywords like “return” aren’t doing precisely the same thing you may be accustomed to in other languages. “Native” syntax in PowerShell would be…
function multiply { param($x,$y) write-output ($x * $y) }
Return and Write-Output aren’t 100% exactly the same, but it’s worth understanding the differences if you’re going to dive into anything more complex.