$(document).ready(function () {

    var columnForm = $("#columnSize").val();
    var rowForm = $("#rowSize").val();

    newGame(columnForm, rowForm);

    $("form").submit(function (event) {
        event.preventDefault();

        $(".table1").empty();

        columnForm = $("#columnSize").val();
        rowForm = $("#rowSize").val();

        newGame(columnForm, rowForm);
    });

    $(document).keydown(function (key) {
        switch (parseInt(key.which, 10)) {
            case 37:
                game.moveLeft()
                break;
            case 38:
                game.moveUp()
                break;
            case 39:
                game.moveRight()
                break;
            case 40:
                game.moveDown()
                break;
            default:
                break;
        }
        refreshData();
    });
});

var newGame = function (columnForm, rowForm) {
    window.game = new Game(columnForm, rowForm);
    window.game.start();

    appendData();
    refreshData();
}

var refreshData = function () {
    for (var x = 1; x <= game.rowLength * game.colLength;) {
        for (var i = 0; i < game.rowLength; i++) {
            for (var j = 0; j < game.colLength; j++) {
                if (game.board[i][j] === 0) {
                    $('.data' + x).html(" ")
                    $('.data' + x).css('background-color', '#E6CCCC')
                    $('.data' + x).css('opacity', '0.4')
                } else {
                    $('.data' + x).html(game.board[i][j])
                    $('.data' + x).css('background-color', '#18EC9E')
                    $('.data' + x).css('opacity', '1.0')
                }
                x += 1
            }
        }
    }
}

var appendData = function () {
    for (var x = 1; x <= game.rowLength * game.colLength;) {
        for (var i = 0; i < game.rowLength; i++) {
            $('.table1').append("<tr class=\"row" + i + "\"></tr>")
            for (var j = 0; j < game.colLength; j++) {
                $('.row' + i).append("<td class=\"data" + x + "\"></td>")
                x += 1
            }
        }
    }
}

@@ -1057,73 +1057,8 @@
 ) %7B%0A
-    for (var x = 1; x %3C= game.rowLength * game.colLength;) %7B%0A    
     
@@ -1100,36 +1100,32 @@
  i++) %7B%0A        
- 
-   
 for (var j = 0; 
@@ -1163,20 +1163,16 @@
         
-    
 if (game
@@ -1201,36 +1201,32 @@
                 
-  
-  
 $('.data' + x).h
@@ -1217,25 +1217,29 @@
 $('.data' + 
-x
+i + j
 ).html(%22 %22)%0A
@@ -1246,36 +1246,32 @@
                 
-  
-  
 $('.data' + x).c
@@ -1258,33 +1258,37 @@
     $('.data' + 
-x
+i + j
 ).css('backgroun
@@ -1316,36 +1316,32 @@
                 
- 
-   
 $('.data' + x).c
@@ -1328,33 +1328,37 @@
     $('.data' + 
-x
+i + j
 ).css('opacity',
@@ -1377,20 +1377,16 @@
         
-    
 %7D else %7B
@@ -1386,20 +1386,16 @@
  else %7B%0A
-    
         
@@ -1414,17 +1414,21 @@
 data' + 
-x
+i + j
 ).html(g
@@ -1452,36 +1452,32 @@
                 
-    
 $('.data' + x).c
@@ -1468,25 +1468,29 @@
 $('.data' + 
-x
+i + j
 ).css('backg
@@ -1514,20 +1514,16 @@
 8EC9E')%0A
-    
         
@@ -1542,17 +1542,21 @@
 data' + 
-x
+i + j
 ).css('o
@@ -1575,49 +1575,8 @@
 0')%0A
-                %7D%0A                x += 1%0A
     
@@ -1639,73 +1639,8 @@
 ) %7B%0A
-    for (var x = 1; x %3C= game.rowLength * game.colLength;) %7B%0A    
     
@@ -1686,28 +1686,24 @@
 ) %7B%0A        
-    
 $('.table1')
@@ -1750,28 +1750,24 @@
 %3E%22)%0A        
-    
 for (var j =
@@ -1805,28 +1805,24 @@
             
- 
-   
 $('.row' + i
@@ -1851,17 +1851,21 @@
 data%22 + 
-x
+i + j
  + %22%5C%22%3E%3C
@@ -1875,45 +1875,8 @@
 %3E%22)%0A
-                x += 1%0A            %7D%0A
     

Improve time complexity