new to javascript. What i want this program to do is if the first cell of each row is clicked, I want to highlight that row. If any other cell is clicked, I want to highlight that one cell. I think my logic is correct, if I can get the cell index, I can highlight the correct cell(s) but the number that keeps getting passed into my highlight function is 9. Not sure where I'm going wrong.
window.onload = function() {
  var cells = document.getElementsByTagName("td");
  var theads = document.getElementsByTagName("th");
  for (var i = 0; i < cells.length; i++) {
    cells[i].addEventListener("click", function() {
      highlightCell(i);
    });
  }
    function highlightCell(x) {
      //alert(x + " clicked");
      if (x == 0) {
        //highlight table cells 0,1,2 lightBlue
        //highlight others to white
      } else if (x == 3) {
        //highlight table cells 3,4,5
        //highlight others to white
      } else if (x == 6) {
        //highlight table cell 6,7,8
        //highlight others to white
      } else {
        //highlightCell single table cell clicked
        //hihglight others to white
      }
    }
  }
}
 
     
     
     
    