How to sort random number but appear 8 numbers 1 number each time?

-2

I need to make a draw system that appears one number at a time but there are eight numbers that should appear next to each other more than just turning from 1 to 9 equal this code and in the time interval go one stopping at a time ! Same as mega sena!

<script type="text/javascript">
var nomes = ["1","2","3","4","5","7","8","9",];
function sorteio() {
    var c = document.getElementById('campo');

    var i = 0;
    var velocidade = document.getElementById('speed').value;
    var tempo = document.getElementById('time').value;
    var intervalo = window.setInterval(function() {
                if (i >= nomes.length)
                    i = 0;
                c.value = nomes[i++];
            }, velocidade);
    window.setTimeout(function() {
                clearInterval(intervalo);
                var n = Math.floor(Math.random()*nomes.length);
                c.value = nomes[n];
            }, tempo);
}
</script>
<input type="text" id="campo" name="campo" placeholder="Boa sorte a todos!" readonly="true">



<input type="hidden" value="100" id="speed" name="speed"><br>
<input type="hidden" value="600" id="time" name="time">
<input type="button" onclick="sorteio();" value="Sortear o Ganhador" id="btn" name="btn">
    
asked by anonymous 22.11.2017 / 18:01

1 answer

0

You can do this, remembering that there are several ways to do it (even better than this), but it is an example.

let node = document.getElementById('resultado')
let qtd = 0

function gerarNumero(){
  let numero = Math.random() * (1, 9) + 1
  numero = Math.floor(numero)
  
  node.innerHTML += ' ' + numero 
}

setInterval(function(){
  if(qtd < 10){
    gerarNumero()
    qtd++
  }
}, 3000)
<div id="resultado"></div>
    
22.11.2017 / 18:19