Make infinite count of ordinal numbers and expose in HTML document

1

What I want to know is how can I make a rising counter in pure Javascript 0, 1, 2, ...

I want something automatic, infinite without requiring an integer or negative integer

The count can be started from 0 or 1 onwards ...

Example

</script>

var min = 0    

var max = 9

for (var i = min; i < max; i++) {
  var seq = i/0;
  document.getElementById('num').innerHTML += i
}
<script>

<body>
   <span id='num'>&nbsp;</span>
</body>
    
asked by anonymous 23.01.2017 / 15:14

1 answer

3

Will it be something like this?

const eleResult = document.getElementById('contador');
var n = 0;
window.setInterval(function() {
  eleResult.innerHTML += n+ ' ';
  n++;
}, 100); // ajustas o tempo em milisegundos aqui
<div id="contador"></div>

To set a maximum (in this case 20) you do:

const eleResult = document.getElementById('contador');
var n = 0;
const max = 20;
const conta = window.setInterval(function() {
  eleResult.innerHTML += n+ ' ';
  if(n == max) window.clearInterval(conta);
  n++;
}, 100); // ajustas o tempo em milisegundos aqui
<div id="contador"></div>
    
23.01.2017 / 15:23