title: Uncaught TypeError: cannot set property 'backgroundColor' of undefined javascript
body: <p>I am creating a HTML music production program. I am currently working on the note system for when you click on a note, it switches color to black. But, when I use my Javascript function, it shows the error <code>Uncaught TypeError: cannot set property 'backgroundColor' of undefined</code> 
  <hr>
  Here is my Javascript. it is incomplete, but if anyone can help, that would be great. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var pattern = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  function switchNote(num, note) {
   var trId = document.getElementsByTagName("tr")[note + 8].id;
   pattern[num] = note;
   document.getElementById(trId).lastChild.style.backgroundColor = "#000";
   return "switched";
  }</code></pre>
  </div>
  </div>
  </p>