0
Seen what I tried:
<html>
<body>
<script>
var nome = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
var remover = nome.slice(0);
function shuffle(array) {
return (Math.round(Math.random()) - 1);
remover.splice(array, 1);
}
shuffle(nome);
alert(nome);
</script>
</body>
</html>
But did not know how to add a button for such a purpose and yet this code does not make the purpose.
forehead
el.addEventListener('click', function(){ nome.shift(); });
If it doesn’t work or it’s not what you want you have to explain the question better....– Sergio
The method
shuffle()
is returning a value before you run thesplice()
, maybe that’s the problem.– Gabriel C.
@Diegohenrique what I meant is that if your button runs the method
shuffle(array)
, the problem lies in the fact that it performsreturn (Math.round(Math.random()) - 1);
before executingremover.splice(array, 1);
, thus the method returns before thesplice()
run, and this may be the problem in your code.– Gabriel C.