Uncaught TypeError: Cannot read property 'innerHTML' of undefined

hi, i have a problem with function CheckWin
in IF

function buildBoard()
{
	var rows=document.getElementById("selRowNum").value;
	var cols=document.getElementById("selColNum").value;
	var board = document.getElementById("board");
	//clear board
	if (board.hasChildNodes() )
	{
		board.removeChild(board.firstChild); 
	}
	//create new table
	var table=document.createElement("table");
	board.appendChild(table);
	//add rows and columns
	var rowNum;
	var colNum;
	for (rowNum=0;rowNum<rows;rowNum++)
	{
		var row = document.createElement("tr");
		table.appendChild(row);
		for(colNum=0;colNum<cols;colNum++)
		{
			
			var cell = document.createElement("td");
			row.appendChild(cell);
			cell.innerHTML = rowNum + "," + colNum;
			//cell.onclick=function() {dosomething()};
			cell.onclick=function() {NextStep(cell)};
			
			cell.innerHTML=' ';
			
			}
	}
		var cell=document.querySelectorAll('td');

		

			for(var i=0;i<cell.length;i++){

				cell[i].addEventListener('click',NextStep);
				
				}

		

		
		
	
}

var FirstPlayer='X';


function NextStep(cell){
	
		
	this.innerHTML=FirstPlayer;
	if( FirstPlayer=='X'){
		this.FirstPlayer='O';
	}
	else{
		
			this.FirstPlayer='X';
	}
			
	this.removeEventListener('click',NextStep);
	
		var winner = CheckWin(cell);
		if(winner!=false){
			EndGame(cell)
		}
	
	
	
}	
	function EndGame(cell)
	{
		StopGame(cell);
	}
	function StopGame(cell)
	{
		for(var i=0;i<cell.length;i++){

			cell[i].removeEventListener('click',NextStep);
			
			}

	}

	function CheckWin(cell)
	
	
	{
		
		
		var WiningCombination=[

			[0, 1, 2],
			[3, 4, 5],
			[6, 7, 8],
			[0, 3, 6],
			[1, 4, 7],
			[2, 5, 8],
			[0, 4, 8],
			[2, 4, 6],
										
			
	
		];
		for(var i=0;i<WiningCombination.length;i++){
			
			var wc = WiningCombination[i];
				
				
				if(cell[wc[0]].innerHTML==cell[wc[1]].innerHTML&&cell[wc[1]].innerHTML==cell[wc[2]].innerHTML&&cell[wc[0]].innerHTML!= " ")
			{
				
				
				return cell[wc[0]].innerHTML;
			}
				return false;
		}		

	}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

So at a quick glance, your checkWin(cell) is expecting an array of cells, but you check that from within next(cell) – where cell is a single cell value. Am I right?

In the case of cell being a single value rather than an array, what do you think might be happening when you check if (cell[wc[0]].innerHTML ... )?

I try to make tic tac game. function CheckWin need check all option of this array to check who is winner X or O. Cell this is td i think so, if i think right. i am a beginner .
if (cell[wc[0]].innerHTML ... ) its Permanent if i winner or not.

sometimes it is also write me TypeError: Cannot read property ‘0’ of undefined
in this IF i try understand and sole the problem and i can’t