title: How to add a number to a var every second
body: <p>As a beginner in Javascript, I'm trying to make a clicker game. I don't know how to add a number to a var every second</p>
  
  <p>Below is the code at the moment. I'm not sure how to make one of my "dank miners" automatically add coins every second to the player. Let's say there are two auto miners, then the player earns 4 coins per second. Also how to display how much the player is automatically making.</p>
  
  <p>Thanks!</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-js lang-js prettyprint-override"><code>let borkCoins = 0;
  
  let dankMiner = 0;
  
  const earnBork = () =&gt; {
    borkCoins += 1;
    displayScreen();
  };
  
  const buydankMiner1 = () =&gt; {
  
    if (borkCoins &gt;= 20) {
      dankMiner += 1;
      borkCoins -= 20;
      displayScreen();
    } else {
      alert("Insufficient funds!")
    }
  };
  
  const displayScreen = () =&gt; {
    document.getElementById("bork-coins").innerText =
      borkCoins;
    document.getElementById("dankMiner").innerText =
      dankMiner;
  };
  
  displayScreen();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h3&gt;Your BorkCoins: &lt;span id="bork-coins"&gt;&lt;/h3&gt;
  
  &lt;img src="https://i.pinimg.com/736x/ef/6a/cf/ef6acfc481b76637b71d4a71db7de82a--dog-birthday-animal-memes.jpg"
      height="80" width="80" id="bork-coins" onclick="earnBork();"&gt;
      
        &lt;p&gt;Click on Gabe the Doggo to earn a BorkCoin!&lt;/p&gt;
        
         &lt;h3&gt;Shop&lt;/h3&gt;
         
         &lt;p&gt;Dank Miner &lt;i&gt;(2 BorkCoins/sec)&lt;/i&gt;
      &lt;br&gt;Your Dank Miner(s): &lt;span id="dankMiner"&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;button id="dank-miner" onclick="buydankMiner1();"&gt;Buy 1 (20 BorkCoins)&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>