I tried to write a script that increments a variable value, every time a button is clicked.

HTML Code:
  <script type="text/javascript">

  // if the count variable is undefined, set its value to zero
  if(! count) {
  var count = 0;
  }

  // function to increment value of count variable
  incrementCount() {
    count++;
  }
  </script> 
   
  <!-- button to call incrementCount() function, on click -->
  <form>
    <input type="button" value="Count"  onclick="incrementCount()">
  </form> 
  <br />
  
  <script type="text/javascript">
  // output count variable
  document.write(count);
   </script>
Unfortunately the script is not working. Could you please tell me why?

Thanks!