title: How can I stop my audio from looping in an if-else statement?
body: <p>The audio is playing in a loop as per the <code>if</code> statement, but it is not pausing as per the <code>else</code> statement. Why is this happening?</p>
  <p>I also tried:<br />
  <code>if(...) { ... } else if(...) { ... }</code><br />
  because if I use <code>else</code> on its own then nothing works.</p>
  <p>What am I doing wrong?</p>
  <p>Here is my code:</p>
  <pre><code>    function loop(){
          var audio1 = new Audio('./sounds/tom-1.mp3');
          var input1 = document.getElementById('input1');
          if(input1.checked == true) {
              audio1.play();
              audio1.loop = true;
          } else if (input1.checked == false) {
              audio1.pause();
              audio1.loop = false;
          }
      }
  </code></pre>
  <p>And the HTML:</p>
  <pre><code>    &lt;label class=&quot;switch&quot;&gt;
          &lt;input type=&quot;checkbox&quot; id=&quot;input1&quot; onclick=&quot;loop()&quot;&gt;
          &lt;span class=&quot;slider round&quot;&gt;&lt;/span&gt;
      &lt;/label&gt;
  </code></pre>