title: Javascript, Uncaught TypeError: Cannot read property "cells" of undefined
body: <p>I'm trying to work with a table in Javascript.</p>
  
  <p>I have a function to create an empty table,</p>
  
  <pre><code>//This function will create an empty table of a length of vars+1
  //This function will create the header slots as well as empty data slots
  function empty_Table(){
          document.write("&lt;table border=\"1\" id=\"myTable\" &gt;");
          var my_Structure = steps_Structure(steps);
          var vars = my_Structure[0].second.split(",");//This will create an array,str, of multiple variables
          //first row
          document.write("&lt;TR&gt;");
          for (var i = 0; i&lt;vars.length+2; i+=2){
                  document.write("&lt;TH&gt;&lt;/TH&gt;");
          }
          document.write("&lt;/TR&gt;");
          //second row
          document.write("&lt;TR&gt;");
          for (var i = 0; i&lt;vars.length+2; i+=2){
                  document.write("&lt;TD&gt;&lt;/TD&gt;");
          }
          document.write("&lt;/TR&gt;");
          //third row
          document.write("&lt;TR&gt;");
          for (var i = 0; i&lt;vars.length+2; i+=2){
                  document.write("&lt;TD&gt;&lt;/TD&gt;");
          }
          document.write("&lt;/TR&gt;");
          document.write("&lt;/Table&gt;");
          return;
  }
  </code></pre>
  
  <p>and a function to modify that table,</p>
  
  <pre><code>//This function is to begin drawing the variable display table
  //This function should create a dynamic table that grows depending on the values in steps
  function draw_Table(){
          var my_Structure = steps_Structure(steps);
          empty_Table();
          var myTable = document.getElementById('myTable');
          //draw first row
          var vars = my_Structure[0].second.split(",");//This will create an array, of multiple variables
  
          myTable.rows[0].cells[0].innerHTML = 'Variables:';
          //for (var i = 0; i&lt;vars.length; i+=2){
                  //document.write("&lt;TH&gt;",vars[i],"&lt;/TH&gt;");
          //}
  
          //draw second row
          var pairs = my_Structure[step_Cur].second.split(",");                                                                                  
          myTable.rows[1].cells[0].innerHTML = 'Current Value:';
          //for (var i = 1; i&lt;(pairs.length); i+=2){
                  //document.write("&lt;TD&gt;",pairs[i],"&lt;/TD&gt;");
          //}
          //third row                                                                                                    
          myTable.rows[2].cells[0].innerHTML = 'Last Value:';
  }
  </code></pre>
  
  <p>3 lines are giving me trouble</p>
  
  <pre><code>myTable.rows[1].cells[0].innerHTML = 'Variables:';
  myTable.rows[2].cells[0].innerHTML = 'Current Value:';
  myTable.rows[3].cells[0].innerHTML = 'Last Value:';
  </code></pre>
  
  <p>In chrome, I'm seeing the error "Uncaught TypeError: Cannot set property 'innerHTML' of undefined" but have no idea how to fix it. </p>
  
  <p>I am not a javascript user -- I was just given an assignment to write a tool for displaying the steps in solving a function -- to this regard, I have very little javascript knowledge and am seriously struggling with this table</p>
  
  <p>How it ~should~ work:  Given list of variables and their values
  make a table of 3 rows, number of columns corresponding to amount of variables passed.</p>
  
  <pre><code>   Variables:|   a  |   b  |  c
   Current Val:| val1 | val2 | val3
  previous val:| val1 | val2 | val3
  </code></pre>
  
  <p>where previous val shows the values of the previous step of the function, current val shows the current values of each of the variables of the function, and variables gives variables.</p>
  
  <p>The variables and headers are constant upon table creation, the values in the table will change with each time a "next"/"back" button is pressed to display the next/previous step.</p>
  
  <p>Thank you for any help you can provide!</p>
  
  <p>EDIT: Found the bugs with the help of this great community -- The "cells" of undefined bug was caused by an off-by-one subscript, the original bug was caused by creating my table wrong. I closed <code>&lt;TR&gt;</code> before I actually added data to it.</p>