title: It does not use the timeout on the loop
body: <p>Im trying to put this in the console of a website so it clicks something then presses then click another button to exit and then start over so it just spams like that. It works the first time but when the loop comes back its does not use the timeout so it tries to click &quot;document.getElementsByClassName(&quot;fa fa-times&quot;)[0].click();&quot; but since the delay has not happened yet it tries to click something that does not exist</p>
  <pre><code>const n = 7;
  
  var delayInMilliseconds = 1000;
  
  for (let i = 1; i &lt;= n; i++) { 
  
  console.log(`I love JavaScript.`);
   
    document.getElementById(&quot;viewer_link_1569243&quot;).click();
  setTimeout(function() {
  document.getElementsByClassName(&quot;fa fa-times&quot;)[0].click();
   }, delayInMilliseconds);
  
  }``` 
  </code></pre>