Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Cookie - Countdown
    primarykey
    data
    text
    <p>I have an issue with some JS code.</p> <p>I'm trying to get a countdown to start at a random number between 2 points (in this example 50 &amp; 60) and countdown at random intervals. If the user refreshes, I want the countdown to continue from where it was last at before the refresh. I've managed to get so close but now (especially in FF) I keep getting (NaN) as the output.</p> <p>Can someone please save me from smashing my laptop up?? :)</p> <p>Thanks</p> <pre><code>&lt;script&gt; var minSpaces = 50; //Minimum spaces to start with var maxSpaces = 60; //Maximum spaces to start with var maxDecTime = 6000; //Max time interval between decrements var minDecTime = 300; //Min time interval between decrements var redirectWhenDone = 0; //Redirect = 1 set to 0 for no redirect var stopSpaces = 3; //Number it will stop at if not using redirect var redirectLocation = 'http://www.google.com'; if(document.cookie) { maxSpaces = parseInt(document.cookie); minSpaces = parseInt(Math.max(maxSpaces-5, 1)); } var spaces = Math.floor(Math.random()*(maxSpaces-minSpaces+1)+minSpaces); function updateSpaces() { spaces--; document.cookie = spaces+'; expires=Thu, 2 Aug 2015 20:47:11 UTC; path=/'; document.getElementById('spaces').innerHTML = '&lt;span style="color:orange;"&gt;('+spaces+')&lt;/span&gt; orders left!'; var intvl = Math.round(Math.random()*maxDecTime) + minDecTime; if(spaces&gt;stopSpaces){ setTimeout(updateSpaces, intvl); } else {//No spaces left, redirect! if(redirectWhenDone==1) { window.top.location = redirectLocation; } }} window.onload=updateSpaces; &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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