Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to increase variable by (x) units every second and then use variable with Date() to determine how many units since first of month
    text
    copied!<p>For the sake of simplicity, lets say I have to build a page that is continuously updating and displaying how many puppies, kittens and rats are being born per second. Like a counter or timer.</p> <p>I also have to display how many puppies, kittens and rats have been born since 6am and since the start of the month. </p> <p>What I can't figure out is how to determine how many puppies, kittens and rats have been born since 6am and since the star of the month using Date() and have that amount continuously update.</p> <p><strong>HTML</strong></p> <pre><code>&lt;section id="s01"&gt; &lt;h1&gt;if 3 puppies are born every second&lt;/h1&gt; &lt;b id="badge01" class="now"&gt;0&lt;/b&gt; puppies have been born so far.&lt;br&gt; &lt;b class="morning"&gt;?&lt;/b&gt; puppies have been born since this 6 a.m. morning.&lt;br&gt; &lt;b class="month"&gt;?&lt;/b&gt; puppies have been born since the first of this month. &lt;/section&gt; &lt;section id="s02"&gt; &lt;h1&gt;if 5 kittens are born every second&lt;/h1&gt; &lt;b id="badge02" class="now"&gt;0&lt;/b&gt; kittens have been born so far.&lt;br&gt; &lt;b class="morning"&gt;?&lt;/b&gt; kittens have been born since this 6 a.m. morning.&lt;br&gt; &lt;b class="month"&gt;?&lt;/b&gt; kittens have been born since the first of this month. &lt;/section&gt; &lt;section id="s03"&gt; &lt;h1&gt;if 7 rats are born every second&lt;/h1&gt; &lt;b id="badge03" class="now"&gt;0&lt;/b&gt; rats have been born so far.&lt;br&gt; &lt;b class="morning"&gt;?&lt;/b&gt; rats have been born since this 6 a.m. morning.&lt;br&gt; &lt;b class="month"&gt;?&lt;/b&gt; rats have been born since the first of this month. &lt;/section&gt; </code></pre> <p><strong>JS</strong></p> <pre><code>var now = new Date(); var dayOfMonth = now.getDate(); setInterval(function () { // 3 puppies born every second $('#badge01').html(parseInt($('#badge01').html()) + 3); // 5 kittens born every second $('#badge02').html(parseInt($('#badge02').html()) + 5); // 7 rats born every second $('#badge03').html(parseInt($('#badge03').html()) + 7); }, 1); </code></pre> <p>My JSFiddle is here - <a href="http://jsfiddle.net/gJy4x/6/" rel="nofollow">http://jsfiddle.net/gJy4x/6/</a> (I'm new to JS so please bear with me.) </p>
 

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