JSFiddle - React, Tailwind, and code Playground

JavaScript

function drawSnake(){
    var ss = new Snake(250,250,-1,0);
    ss.create();
    //ctx.fillStyle = "white";
    for(i=ss.snakeBlock.length; i>=0;i--){
        var s = ss.snakeBlock[i];
        //ctx.fillRect(s.xPos,s.xPos,s.height,s.width);
    }
}    

function Block(x,y,w,h){
    this.xPos = x;
    this.yPos = y;
    this.width = w;
    this.height = h;
}

function Snake(x,y,dY,dX){
    this.snakeBlock = [];
    this.length = 20;
    this.xPos = x;
    this.yPos = y;
    this.dirX = dX;
    this.dirY = dY;    
}

Snake.prototype.create = function(){
    for (var i = 0; i <= length; i++) {
        this.snakeBlock.push(new Block((this.xPos-(i*10))*this.dirX, (this.yPos-(i*10))*this.dirY,10,10));
    };
}

drawSnake();
console.log('done');