title: Onclick function in the <script> tag instead of the <button> not working
body: <p>I'm trying to use the onClick() function inside the script tag.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script&gt;
          const btn = document.getElementById(&quot;mainButton&quot;);
          btn.onclick = function(){
              alert(&quot;You shouldn't have clicked this button!&quot;);
          };
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;button id=&quot;mainButton&quot;&gt;Do not click this button&lt;/button&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>When I looked on the internet to find the syntax to do this it looked something like the above.</p>
  <p>However when I run this script it doesn't work and I have no clue why and Any other way I've tried becomes a syntax error.</p>