I am writing a snake.
You need to move 4 cells (the length of the snake) by pressing the arrow keys.
I have a condition written, but I do not know how to proceed. How can this be implemented?
Here is the code:
(function() { var rows = ''; for(var i=0;i<=15;i++) { rows += '<tr class="row" + i'; for(var j=0;j<=25;j++) { rows += '<td></td>'; } rows += '</tr>'; } document.getElementById('table').innerHTML = rows; addEventListener("keyup", function(event) { if (event.keyCode == 86) document.body.style.background = ""; }); }()); #table { margin: 0 auto; } td { width: 10px; height: 10px; border: 1px solid black; } tr:nth-child(1) td:nth-child(1) { background: red; } tr:nth-child(1) td:nth-child(2) { background: red; } tr:nth-child(1) td:nth-child(3) { background: red; } tr:nth-child(1) td:nth-child(4) { background: red; } <table id="table"> <tr class="row"> <td></td> </tr> </table>
setinterval? - Igor