Unfixable syntax error?

This topic contains 2 replies, has 3 voices, and was last updated by  Don Jones 3 years ago.

  • Author
  • #22516

    Mason Emlen

    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?

  • #22518

    Dave Wyatt

    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
  • #22519

    Don Jones

    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 {
      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.

You must be logged in to reply to this topic.