How to enable button onClick functions and java script in wordpress post

I am trying to add the below codes to WordPress, however, wordpress always gives me error 404 whenever I try to update. I’m new to coding. So would appreciate some help.

Codes that I want to add into wordpress post
Image of my error
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>

</head>
<body>


  Code 1: <input type="text" id="code1">
  <br>
  <p id="code1ans"></p>

  Code 2: <input type="text" id="code2">
  <br>
  <p id="code2ans"></p>

  Code 3: <input type="text" id="code3">
  <br>
  <p id="code3ans"></p>

  Code 4: <input type="text" id="code4">
  <br>
  <p id="code4ans"></p>


  <button onclick="myFunction()">Submit</button>

    <script>
      function myFunction() {
          var code1 = document.getElementById("code1").value;
          var code2 = document.getElementById("code2").value;
          var code3 = document.getElementById("code3").value;
          var code4 = document.getElementById("code4").value;
          document.getElementById("code1ans").innerHTML = code1;
          document.getElementById("code2ans").innerHTML = code2;
          document.getElementById("code3ans").innerHTML = code3;
         document.getElementById("code4ans").innerHTML = code4;
      }
    </script>


  </body>
</html>

Leave a Comment