title: If A and B are the same after X seconds, reduce A
body: <p>I'm presently trying to learn JavaScript by creating an incremental game.</p>
  <p>One of my variables (called 'renown') should always be going up if the player is interacting or has &quot;hired&quot; recruits. However, if they're idle and recruits have &quot;died&quot;, I would like renown to decrease slowly and the rate of decrease to increase over time until renown is 0.</p>
  <p>I think I've figured out the renown decrease multiplier, but the part I'm struggling with is the &quot;idle&quot; state.</p>
  <p>This is the code I presently have:</p>
  <pre><code>window.setInterval(function () {
      var lastrenown = renown;
      document.getElementById(&quot;lastrenown&quot;).innerHTML = lastrenown;
  }, 3000);
  
  function renowndeccalc() {
      if (renown != 0) {
          if (renown == lastrenown) {
              renown = renown - (100 * idlerenownmultiplier);
              document.getElementById(&quot;renown&quot;).innerHTML = renown;
              idlerenownmultiplier++
          }
      }
  }
  
  setInterval(renowndeccalc, 5000);
  </code></pre>
  <p>The intention here being that every 3 seconds 'lastrenown' is updated to match renown. If the player or recruits are active, lastrenown should never equal renown.</p>
  <p>If the player or recruits aren't active, lastrenown should equal renown, at which point every 5 seconds renown decreases by 100 * the multiplier.</p>
  <p>What's actually happening is renown doesn't change at all. If I remove the 0 check so the function is as follows:</p>
  <pre><code>function renowndeccalc() {
          if (renown == lastrenown) {
              renown = renown - (100 * idlerenownmultiplier);
              document.getElementById(&quot;renown&quot;).innerHTML = renown;
              idlerenownmultiplier++
          }
  }
  
  </code></pre>
  <p>Renown will go down by 100 after 5 seconds and then not repeat.</p>
  <p>My understanding is that setInterval should cause the function to repeat as often as you determine, but <em>something</em> in the logic is causing my script to not work as intended.</p>
  <p>Any help with this would be greatly appreciated.</p>