title: Problem on condition with window.setTimeout
body: <p>I am working on a website which has a loading page that lasts 5 seconds where you can choose if you want to activate the autoplay or not. Even when I do a condition, the autoplay still runs for some reason. Here's the code, hopefully someone can help.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body .loading {
    text-align: center;
  }
  
  body #content {
    display: none;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!doctype html&gt;
  &lt;html lang=en&gt;
  
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Home&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
    &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;div class="loading"&gt;
      &lt;input type="button" value="Click Here to mute" class="autoplay" id="autoplayno" /&gt;
    &lt;/div&gt;
  
    &lt;div id="content"&gt;
      &lt;iframe class="embed-responsive-item" id="iframesc" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/users/334742776&amp;color=%23ff5500&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;show_teaser=true&amp;visual=true&amp;start_track=1"
        allow="autoplay"&gt;&lt;/iframe&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"&gt;&lt;/script&gt;
  &lt;!--Loading Page--&gt;
  &lt;script&gt;
    $(".loading").fadeOut(5000, function() {
      $("#content").fadeIn(2000);
    });
  &lt;/script&gt;
  
  &lt;!--The script which is not working--&gt;
  &lt;script&gt;
    var hasBeenClicked = false;
    $("#autoplayno").click(function() {
      hasBeenClicked = true;
    });
  
    if (hasBeenClicked) {
      $("#iframesc").attr("src", "https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/users/334742776&amp;color=%23ff5500&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;show_teaser=true&amp;visual=true&amp;start_track=1");
      $("#autoplayno").attr("value", "Sound mutted");
    } else {
      window.setTimeout(function() {
        $("#iframesc").attr("src", "https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/users/334742776&amp;color=%23ff5500&amp;auto_play=true&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;show_teaser=true&amp;visual=true&amp;start_track=1")
      }, 4000)
    }
  &lt;/script&gt;
  
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>