title: simple Javascript For Loop with if else statement
body: <p>I am new to js and I am trying out what I think should be a simple for loop. Basically I have a table with some strings in it and I want to change the background color of that table data column depending on the string.</p>
  
  <p>Here is what I have </p>
  
  <pre class="lang-js prettyprint-override"><code>for (var i = 0; i &lt; 50; i++) {
    if (document.getElementById("td" + [i]).innerText == "TRUE") {
      document.getElementById("td" + [i]).style.backgroundColor = "green";
    } else {
      document.getElementById("td" + [i]).style.backgroundColor = "red";
    }
  }
  </code></pre>
  
  <p>It might be worth mentioning that the innerText is actually an API response that already uses an if statement inside a for loop </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;?php
    for ($i=0; $i &lt; 50 ; $i++) {
      $type = $logs[$i]['type'];
      echo '&lt;tr&gt;';
      echo '&lt;td id="td' .$i. '"&gt;';
      if ($type == 2) {
        echo "TRUE";
        echo '&lt;br /&gt;';
      }
      else {
        echo "FALSE";
      }
      echo '&lt;/td&gt;';
  </code></pre>
  
  
  
  <p>I am sure my code is wrong on many levels but it is working excep trying to run the for loop and change the background color. I don't think the js is correct in picking up the td0, td1, td2, etc.</p>