title: javascript stop audio from button click
body: <p>When the function generate is called, the sound should be played. If button is triggered sound sound should be stopped. What's the best way to do this?</p>
  
  <pre><code>    &lt;script&gt;
  
      var audio = new Audio('assets/spin.mp3');
  
          function generate()
              {
  
                  /* some code goes here*/
                  audio.play();
              }
  
      &lt;/script&gt;
  
      &lt;button onClick="game.rotationAngle=0; game.draw();generate();audio.stop();"&gt;start&lt;/button&gt;
  </code></pre>
  
  <p>It's a kind of reset I need to perform when the button is triggered. That's why the sound needs to be stopped, before it will run again.</p>
  
  <p>I get this error in debug:
  <a href="https://i.stack.imgur.com/95sEn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/95sEn.png" alt="error"></a></p>