Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The main issue here was scoping, as Femi suggested before. You <strong>must</strong> move <code>var timerGetContent = null;</code> outside the function declaration. You also had a logic error in the first condition, <code>status == "login"</code>. You were setting the <code>timerGetContent</code> intervalID to null without clearing it first.</p> <p>So, if you called <code>setTimers("login");</code> after calling <code>setTimers("negitive");</code> without calling <code>setTimers("positive");</code> to first clear the interval, you would always have at least one interval going.</p> <p>I replaced your function calls with console.log statements for testing:</p> <pre><code>var tray_count = 0; var timerGetContent = null; function setTimers(status) { if(status == "login") { tray_count = 0; // Setting the intervalID to null will NOT clear the interval // If we do not clear the interval, calling setTimers('login') // will create a new interval and make previous interval // "unclearable" every time it is called clearInterval(timerGetContent); timerGetContent = null; timerGetContent = setInterval(function() { console.log('login intervalling') },400); } else if(status == "negitive") { tray_count--; if(tray_count == 0 &amp;&amp; timerGetContent == null) { timerGetContent = setInterval(function() { console.log('negitive intervalling') },400); alert("inside negitive"); } } else if(status == "positive") { tray_count++; clearInterval(timerGetContent); // calling clearInterval does not actually unset the intervalID variable // so we need to set it to null manually timerGetContent = null; timerGetBlasts = null; } } </code></pre> <p>Update 2014-07-14: Fixed a formatting typo --cbarrick</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload