Search code examples
pythonhtmlgithubonclicksyntax-error

Trouble having my RPS game show up with onClick button


<!DOCTYPE html>
<html>
<head>
<title>Play Rock Paper Scissors (MK Edition)</title>
</head>
<body>
<button onclick="Play Rock Paper Scissors(MK Edition)">Play Rock Paper Scissors (MK Edition)</button>
<script>
function Play Rock Paper Scissors(MK Edition) {
// Get the path to the Python script.
var pythonScriptPath = "path/to/python/script.py";
  // Run the Python script.
  subprocess.run(["python", pythonScriptPath]);
}

I am receiving two syntax errors in my code when I am trying to have my rock paper scissor game pull up when I click the play button.

I'm still trying to rework it and look for any grammatical errors etc but I'm not sure if it's that. The error messages I see say "uncaught syntaxerror: missing ( before formal parameters" and "uncaught syntaxerror: unexpected token: identifier". My expectations are when a user clicks on the play rock paper scissors button the rock paper scissors game prompts will pull up so you can play.


Solution

  • from a first glance it seems you have a syntax error in your Javascript function name. you can't have spaces in the function name, and parentheses should be reserved for parameter declarations. you can apply these changes like this:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Play Rock Paper Scissors (MK Edition)</title>
    </head>
    <body>
      <button onclick="playRockPaperScissors()">Play Rock Paper Scissors (MK Edition)</button>
      <script>
        function playRockPaperScissors() {
          // Get the path to the Python script.
          var pythonScriptPath = "path/to/python/script.py";
          
          // Run the Python script.
          subprocess.run(["python", pythonScriptPath]);
        }
      </script>
    </body>
    </html>
    

    the onClick attribute of the button now calls the playRockPaperScissors() function.