hello everyone! can please somebody help me to understand how to compare 2 dimensional Arrays value with a Index of li Elements. This Exemplo I will like to use for my TicTacToe game.
//here Select my List Elements:
let liList = document.querySelectorAll('.boxes li');
//and here the 2 dimensional arrays with possible combinations to win the game
const horizontalBoxes = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8]
];
const vertical = [
[0, 3, 6],
[3, 4, 5],
[6, 7, 8]
];
const diagonal = [
[0, 4, 8],
[6, 4, 2]
];
so now I have:
variable liList which has this output a NodeList(9) [li.box, li.box, li.box, li.box, li.box, li.box, li.box, li.box, li.box]_ and the 2 dimensional Arrays
Now what I want to do is:
to proof if those index : [li.box, indexli.box, li.box, li.box, li.box, li.box, li.box, li.box, li.box] are the same to one of my 2 dimensional array.
Like this:
Index of my li list: 0 , 4, 8 is equal horizontalBoxes [[0, 1, 2]] if yes display winner
if not compare 0 , 4, 8 again with next array: horizontalBoxes [[3, 4, 5]] and so on...
Here you find a small code of what i mean and trying to do: https://codepen.io/Alanes/pen/WMaBMB?editors=1111