Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll note that your code is using <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval" rel="nofollow"><code>setInterval()</code></a>. This global JavaScript function is used for periodically executing code at a given time interval. It takes two arguments for its typical usage (which is the way you are using it here). It returns a unique ID that can be used to identify your particular interval function (since multiple ones can be set up simultaneously).</p> <p>The first argument is a function to be executed on the interval. Your function is the anonymous function:</p> <pre><code>function() { value = ((+value) + .1).toFixed(1); if (value == 80.5) clearInterval(interval); $('p').html(value + '%'); } </code></pre> <p>This function will increase the percentage progress on each execution.</p> <p>The second argument is an integer number for the number of milliseconds (thousandths of a second) to let elapse before the function from the first argument is executed. This is the key part for your question, I believe. Your code has <code>2</code> (on the last line of your posted code), so it will wait 2 milliseconds before executing your function (which increments the percentage progress), and then it will wait 2 more milliseconds, then execute the same function again, etc.</p> <p>By simply changing the value of the second argument, you can change how fast or slow your function executes each time, which changes how fast or slow your percentage increases. So if you set it to <code>500</code>, then <code>setInterval</code> will wait for a half a second before each execution of the function.</p> <p>You can read about the other JavaScript timer functions <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Timers" rel="nofollow">here</a>, in particular about <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.clearInterval" rel="nofollow"><code>clearInterval()</code></a>, which your code uses in the anonymous function to end the interval when you reach <code>80.5%</code>.</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. 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