JSFiddle - React, Tailwind, and code Playground

by Amar Nyayapati

HTML

<div id="snake"></div>
<input type="button" value="start" id="bt1" >
<script>
    $("#bt1").click(function(){
        $(document).bind('keydown', function(e) {
            var head = $("#snake"),
            left = 37,
            up = 38,
            right = 39,
            down = 40
    
            switch(e.keyCode){
                case left:            
                        head.animate({"left":"-=10"},"200");
                        break;
                case up:            
                        head.animate({"top":"-=10"},200);
                        break;
                case right:   
                        head.animate({"left":"+=10"},200);
                        break;
                case down:            
                        head.animate({"top":"+=10"},200);
                        break;
            }
        });
    });
    
</script>

CSS

#snake{    
    width:30px;
    height:30px;
    background:green;
    position:absolute;
    top:150px;
    left:150px;
   
 }