title: JavaScript slider puzzle - scrambling values
body: <p>(I'm brand new to JS so bear with me) I am using a table to build a sliding puzzle game. I need a function that will scramble the values, but I am not sure how I should get it to display in the table cells. Right now my code just displays the numbers in order.
   I have two functions - one to build the table and the other to shuffle the values: </p>
  
  <pre><code>    var _r = 3;
      var _c = 3;
  
  
  //initializes the puzzle
  function newPuzzle(r, c)
  {
     var table = document.createElement("table");
     table.id = "myTable";
  
     for (var i = 0; i &lt; r; i++)
     {
        var row = document.createElement('tr');
        for (var j = 0; j &lt; c; j++)
        {
           var column = document.createElement('td');
           row.appendChild(column);    
        }
        table.appendChild(row);
     }
     document.body.appendChild(table);
  
  
     //end of table creation
     //populate the table
     var cell = new Array(r);
     for (var i = 0; i &lt; r; i++)
     {
        cell[i] = new Array(c);
        for (var j = 0; j &lt; c; j++)
        {
           cell[i][j] = i*c + j;
        }  
     }
     cell[0][0] = " ";
  
     for (var i = 0; i &lt; cell.length; ++i)
     {
          var entry = cell[i];
          for (var j = 0; j &lt; entry.length; ++j)
          {
              var n = 0;
              var gridTable = document.getElementsByTagName("table");
              gridTable[0].rows[i].cells[j].innerHTML = cell[i][j];
              document.getElementById("myTable").rows[i].cells[j].id = "even" + (i*c+j);
  
          }    
     }
  
   shuffle();
  }
  
  
  function shuffle()
  {
  
   //declare and populate array
   var _array = new Array();
  
   for (var i = 0; i &lt;= r*c; i++)
   {
     _array[i] = i;
   }
  
   //shuffle tiles
   for (var i = 0; i &lt;= r*c; i++)
   {
     var rand = Math.floor(Math.random() * _array.length) + i;
     var temp = _array[rand];
     _array[rand] = _array[i];
     _array[i] = temp;
   }
  
   //check to see if puzzle is solveable
   var count = 0;
   for (var i = 0; i &lt;= r*c; i++)
   {
     for (var j = i; j &lt;= r*c; j++)
     {
        if (_array[j] &lt; _array[i])
        {
           count++;
        }
     }
   }
  
   if (Math.floor(count/2) != count/2)
   {
     shuffle();
   }
   else
   {
     for (var i = 0; i &lt; r*c; i++)
     {
  
        //This is where I'm not sure what to do
  
        document.getElementsByTagName("td")[i].innerHTML = _array[i]+1;
     }
   }
  
  }
  </code></pre>