I'm currently building a roulette game. To the simulate wheel spinning I'm use this code:
function getColor(item){
var x = document.getElementById(item);
return x.className;
}
function spin() {
spinning = true;
for (let i = 0; i < options.length; i++) {
document.getElementById("wheel").style.backgroundColor = getColor(options[i]);
document.getElementById("number").innerHTML = options[i];
//sleep for 100ms
}
spinning = false;
}
It does what I need but it does it too fast so you can't see every number go by. Is there a way to make the program sleep for 100ms every iteration. When I try to use setTimeout it doesn't pause the code. I've looked around at other question but they all say to use the timeout and it doesn't work for me.