dynamic table that needs random colors
<p>I need to do for homework somthing Relatively simple....</p>

<p>i need to to dynamic table that get's random colors and random number for each  in the table...
now, my problem is a strange one... </p>

<p>there are sum varaible's that i give them a number and Expect that id do somthing simple like this  sum=4+2
the result he give me is 42 Instead of 6...</p>

<p>this is my code, i hope somone can help me..</p>

<pre><code>&lt;script type="text/javascript" language="javascript"&gt;
function buildTable(){
   // gets the number that inserted to the text box
   rows=document.getElementById("txtNumber").value;

   // alert error masssege
   // if    (1): the textBox(txtNumber)is empty
   // or if (2): the value in the text box is not a number
   // or if (3): the value in the text box is not between 1-15
   if (rows=="" || !IsNumeric(rows) || rows&lt;1 || rows&gt;15)
      alert("invalid number!");
   else{
      ////////////////////// Add your code here ////////////////////// 

      //varables
      randomNumbers=new Array();
      var index=0;

      for(var h=0;h&lt;(rows*4)-4;h++){
         randomNumbers[h]=Math.floor(Math.random()*101);
      }

      //here start printing table + print first line to the html document
      document.write("&lt;table&gt;");
      getFirstrow(randomNumbers,rows,index);
      index=rows;
      //print table with out first or last row
      for(var i=0;i&lt;rows-2;i++){
         var newColor=randomColor();
         document.write(index+" ");
         document.write("&lt;tr&gt;");
         document.write("&lt;td style=background-color:"+newColor+"&gt;"+randomNumbers[index]+ "&lt;/td&gt;");
         for(var j=0;j&lt;rows-2;j++){
            document.write("&lt;td&gt;"+ "&lt; src='face.png' /&gt;"+ "&lt;/td&gt;");
         }
         newColor=randomColor();
         document.write("&lt;td style=background-color:"+newColor+"&gt;" + randomNumbers[index+1]+ "&lt;/td&gt;");
         document.write("&lt;/tr&gt;");
         index=index+2;
      }//end of for

      index=(rows*3)-4;
      //print last row of table
      getLastrow(randomNumbers,rows,index);
      document.write("&lt;/table&gt;");
      getSum(randomNumbers);
   }//End of Else
}//end of buildTable

//////////////////////////////////////function get first  row//////////////
function  getFirstrow(randomNumbers,rows,index){
   document.write("&lt;tr&gt;");
   for(var j=index;j&lt;index+rows;j++){
      newColor=randomColor();
      document.write("&lt;td style=background-color:"+newColor+"&gt;"+ randomNumbers[j]+ "&lt;/td&gt;");
   }
   document.write("&lt;/tr&gt;");
   // return  randomNumbers;
}//end of function

function  getLastrow(randomNumbers,row,index){
   a=(row+(row-2)*2);
   sum=0;
   sum=index+row;

   document.write("&lt;tr&gt;");
   for( j=index;j&lt;sum;j++){
      newColor=randomColor();
      document.write("&lt;td style=background-color:"+newColor+"&gt;"+ randomNumbers[j]+ "&lt;/td&gt;");
      document.write("&lt;p style=color:blue&gt;"+j+"&lt;/p&gt;") ;

      document.write(sum+" ");
   }

   document.write("&lt;/tr&gt;");

   // return  randomNumbers;
}//end of function 

//////////////////////////////////////function that gets random color//////////////////
function getDecimalColor(colorList){
   newColor="#";
   for(x in colorList){
      switch(colorList[x]){
      case 10:colorList[x]="AA";break;
      case 11:colorList[x]="BB";break;
      case 12:colorList[x]="CC";break;
      case 13:colorList[x]="DD";break;
      case 14:colorList[x]="EE";break;
      case 15:colorList[x]="FF";break;
      default:colorList[x]=colorList[x].toString()+ colorList[x].toString();
      }
      newColor+=colorList[x];
   }//end of for
   return newColor;
}//END OF FUNCTION 

///////////////////////////function for random color//////////////////
function randomColor(){
   var color=new Object();
   var colorarray=new Array();
   color.r=Math.floor(Math.random()*16);
   color.g=Math.floor(Math.random()*16);
   color.b=Math.floor(Math.random()*16);
   colorArray=new Array(color.r,color.g,color.b);
   color.decimalcolor=getDecimalColor;

   newColor = color.decimalcolor(colorArray);
   return newColor;
}//end of random color

///////////////////////////get random numbers///////////////////////////
function getRandomNumbers(){
   return Math.floor(Math.random()*101)
}

//////////////////////////get sum of all the random number////////////////////////////////////
function getSum(randomNumbers){
   var sum=0;
   for(x in randomNumbers){
      sum+= randomNumbers[x]; 
   } 
   alert("the sum is: "+sum);  
}

// help function that checks if a text is a number
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i &lt; sText.length &amp;&amp; IsNumber == true; i++){
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}//end of is numeric
&lt;/script&gt;
</code></pre>
