I have a program which should randomly change the position of a cross in a table every half a second forever, but I can't find a way to make the program wait for half a second without it hanging.
The following is my code, where the sleep(0.5)
should be switched with something different:
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<td id="0x0">X</td>
<td id="1x0">X</td>
<td id="2x0">X</td>
</tr>
<tr>
<td id="0x1">X</td>
<td id="1x1">X</td>
<td id="2x1">X</td>
</tr>
<tr>
<td id="0x2">X</td>
<td id="1x2">X</td>
<td id="2x2">X</td>
</tr>
</table>
<script>
for(;;) {
var x = Math.floor(Math.random()*2);
var y = Math.floor(Math.random()*2);
id = x.toString() + "x" + y.toString();
document.getElementById(id).innerHTML = "O";
sleep(0.5);
document.getElementById(id).innerHTML = "X";
}
</script>
</body>
</html>