title: javascript: backgroundColor not working on a <li> element
body: <p>im trying to change the background color of this <code>&lt;li&gt;</code> element but I'm  getting error <code>Uncaught TypeError: Cannot set properties of undefined (setting 'backgroundColor')</code>. i  have been trying to fix this for hours but nothing works. As you can see, I want it to change the background color of the rows element in an if statement and below is my JS code.</p>
  <pre><code>var vals;
  var rows;
  var sum;
  var rowsarr = [];
  var avg;
  
  function obser1() {
      const trades = document.querySelector('.scrollbar-dark');
      const observer = new MutationObserver(function (mutations) {
          mutations.forEach(function (mutation) {
              if (mutation.addedNodes.length) {
                  vals = [...mutation.addedNodes[0].querySelectorAll(&quot;span&quot;)].map(span =&gt; span.textContent);
                  if (vals.length == 4) {
                      rows = vals[2];
                      rowsarr.push(rows);
                  }
                  if (vals.length == 3) {
                      rows = vals[1];
                      rowsarr.push(rows);
                  }
                  console.log(mutation.addedNodes[0]);
                  console.log(rows+&quot;  rows&quot;);
              }
          })
          function arraysum(x, y) {
              return parseFloat(x) + parseFloat(y);
          }
          sum = rowsarr.reduce(arraysum);
          console.log(rowsarr.length + &quot;  length&quot;);
          if (rowsarr.length &gt;= 100 &amp;&amp; rowsarr.length&lt;105) {
              avg = sum / 50;
              console.log(&quot;average is  &quot; + avg);
          }
          /*This is the problem*/
          if (rows &gt; avg) {
              console.log(rows + &quot;  large&quot; + &quot;  average  &quot; + avg);
  
              rows.style.backgroundColor = &quot;white&quot;;
          }
      });
      observer.observe(trades, {
          childList: true,
          subtree: true,
          attributes: true,
          characterData: true
      })
     
  }
  
  window.setTimeout(btn4, 1000);
  window.setTimeout(obser1, 1700);
  </code></pre>