I was trying to make a script that draws 6 numbers from 1 - 60, without repetition. The Script is working, but I noticed that as I test / refresh the page, there comes a time when the browser increases memory consumption and the tab stops responding. I imagine it's a problem in the code, could you point out the error?
<script>
var numerosSorteados = function(){
var num = [];
var numero;
var chave = true;
var i = 0;
while( i < 6){
numero = Math.round((Math.random() * 60) + 1);
for(var j = 0; j < i; j++){
if(numero == num[j]){
chave = false;
break;
}
}
if(chave){
num.push(numero);
i++;
}
document.write(numero+"</br>");
chave == true;
}
return num;
}
document.write(numerosSorteados());
</script>