title: How to limit the number of iterations done by setInterval
body: <p>I display video ads to my users. I don't host these ads by the way; I get them from another company. </p>
  
  <p>When ever an ad is clicked it leaves a cookie in the user's browser.
  I've created a function that checks the existence of a cookie every 10 seconds.</p>
  
  <p>What I would like to do is to limit the number of times this function can run or the number of seconds it can run for.</p>
  
  <p>Below is the function:</p>
  
  <pre><code>function checkCookie()
  {
  var cookie=getCookie("PBCBD2A0PBP3D31B");
    if (cookie!=null &amp;&amp; cookie!="")
    {
    alert("You clicked on an ad" );
    }
  
  setInterval("checkCookie()", 10000);
  </code></pre>
  
  <p>So to recap. I want to limit the number of iterations that <code>setInterval("checkCookie()", 10000);</code> can make</p>