var playTable = new Array();
var row = 0, col = 0, rowPosit, colPosit, playElementValue, sorted = 0;

for (; row < 4; row++) {
    playTable[row] = new Array();
    for (; col < 4; col++) {
        playTable[row][col] = 0;
    }
}

function checkSquare(nrow, ncol) {
    if (rowPosit <= nrow && colPosit <= ncol) {
        for (row = 0; row < 2; row++) {
            for (col = 2; col < 4; col++) {
                if (playTable[row][col] == playElementValue && row != rowPosit && col != colPosit) {
                    sorted = 1;
                }
            }
        }
    }
}

for (var elementCount = 0; elementCount < 8; elementCount++) {
    sorted = 0;
    do {
        rowPosit = Math.floor((Math.random() * 4) + 1) - 1;
        colPosit = Math.floor((Math.random() * 4) + 1) - 1;
    } while (playTable[rowPosit][colPosit] != 0);
    do {
        sorted = 0;
        playElementValue = Math.floor((Math.random() * 4) + 1);
        // check if the randow generated number is NOT in the row already
        for (row = rowPosit, col = 0; col < 4; col++) {
            if(playTable[row][col] == playElementValue && row != rowPosit && col != colPosit ) {
                sorted = 1;
                break;
            }
        }
        // check if the randow generated number is NOT in the col already
        for (col = colPosit, row = 0; row < 4; row++) {
            if(playTable[row][col] == playElementValue && row != rowPosit && col != colPosit) {
                sorted = 1;
                break;
            }
        }
        //4 checks for each 2x2 block in the 4x4 playtable - check if the number is already there
        checkSquare(1, 1);
        checkSquare(1, 3);
        checkSquare(3, 1);
        checkSquare(3, 3);
    } while (sorted == 1);
    playTable[rowPosit][colPosit] = playElementValue;
}

@@ -100,16 +100,17 @@
 ;%0A%0Afor (
+ 
 ; row %3C 
@@ -102,32 +102,33 @@
 %0Afor ( ; row %3C 4
+ 
 ; row++) %7B%0A    p
@@ -227,16 +227,59 @@
    %7D%0A%7D%0A%0A
+//checks the 2x2 square for mathing number%0A
 function
@@ -290,17 +290,19 @@
 ckSquare
-(
+ ( 
 nrow, nc
@@ -299,24 +299,25 @@
 ( nrow, ncol
+ 
 ) %7B%0A    if (
@@ -316,16 +316,17 @@
     if (
+ 
 rowPosit
@@ -353,16 +353,17 @@
  %3C= ncol
+ 
 ) %7B%0A    
@@ -626,21 +626,59 @@
    %7D%0A%7D%0A%0A
+//Generates the twodimensional table%0A
 for (
+ 
 var elem
@@ -710,9 +710,10 @@
 t %3C 
-8
+16
 ; el
@@ -724,24 +724,25 @@
 tCount++) %7B%0A
+%0A
     sorted =
@@ -740,24 +740,107 @@
  sorted = 0;
+%0A%0A    //generates the random position and checks if there is a number there already
 %0A    do %7B%0A  
@@ -1006,16 +1006,88 @@
 %5D != 0);
+%0A%0A    //checks if the number is not in the column, row or square already
 %0A    do 
@@ -2012,60 +2012,1073 @@
 1);%0A
-    playTable%5BrowPosit%5D%5BcolPosit%5D = playElementValue;
+%0A    //after all the checks havve passed, the value is assigned to the table%0A    playTable%5BrowPosit%5D%5BcolPosit%5D = playElementValue;%0A%7D%0A%0Avar inputRow = 0, inputCol = 0, elementValue = 0;%0A%0A//get elements for the html 4x4 Sudoku table%0Afunction getTableElements() %7B%0A    for ( var id = 0, inputRow = 0, inputCol = 0 ; id %3C 4 ; id++, inputCol++) %7B%0A        elementValue = playTable%5BinputRow%5D%5BinputCol%5D;%0A        document.getElementById(%220%22).innerHTML = elementValue;%0A    %7D%0A%0A    for ( id = 4, inputRow = 1, inputCol = 0 ; id %3C 8 ; id++, inputCol++) %7B%0A        elementValue = playTable%5BinputRow%5D%5BinputCol%5D;%0A        document.getElementById(%222%22).innerHTML = elementValue;%0A    %7D%0A%0A    for ( id = 8, inputRow = 2, inputCol = 0 ; id %3C 12 ; id++, inputCol++) %7B%0A        elementValue = playTable%5BinputRow%5D%5BinputCol%5D;%0A        document.getElementById(%223%22).innerHTML = elementValue;%0A    %7D%0A%0A    for ( id = 12, inputRow = 3, inputCol = 0 ; id %3C 16 ; id++, inputCol++) %7B%0A        elementValue = playTable%5BinputRow%5D%5BinputCol%5D;%0A        document.getElementById('4').innerHTML = elementValue;%0A    %7D%0A
 %0A%7D%0A

Update sudokuAlg.js