Looking for a push in the right direction. I'm working on a pure javascript logic game where users must get 3 of each colour in each row/column without having 3 of one colour consecutively. What I'm trying to do now is compare the user grid with the solution grid which I have created.
My issue is that it seems as though the only thing I'm currently changing on my grid is the class which holds the css styles of each tile. Since my table is created on the fly via javascript, is there any way I can compare the two tables without having to display my solution grid? I.e [0][0]==[0][0], but I can't figure out what I must do to compare the two.
*I'm not looking to have a function created for me, but rather for a place to start
//6x6 array
var solutionArray = new Array(6);
solutionArray[0] = new Array(6);
solutionArray[1] = new Array(6);
solutionArray[2] = new Array(6);
solutionArray[3] = new Array(6);
solutionArray[4] = new Array(6);
solutionArray[5] = new Array(6);
//6x6 array
var userArray = new Array(6);
userArray[0] = new Array(6);
userArray[1] = new Array(6);
userArray[2] = new Array(6);
userArray[3] = new Array(6);
userArray[4] = new Array(6);
userArray[5] = new Array(6);
var tile = {colour1:blue, colour2:white, colour3:grey};
var z = "";
var blue = tile.colour1 = "blue";
var white = tile.colour2 = "white";
var grey = tile.colour = "grey";
solutionArray[0][0] = blue;
solutionArray[0][1] = white;
solutionArray[0][2] = blue;
solutionArray[0][3] = blue;
solutionArray[0][4] = white;
solutionArray[0][5] = blue;
solutionArray[1][0] = white;
solutionArray[1][1] = blue;
solutionArray[1][2] = white;
solutionArray[1][3] = blue;
solutionArray[1][4] = blue;
solutionArray[1][5] = white;
solutionArray[2][0] = blue;
solutionArray[2][1] = white;
solutionArray[2][2] = blue;
solutionArray[2][3] = white;
solutionArray[2][4] = white;
solutionArray[2][5] = blue;
solutionArray[3][0] = white;
solutionArray[3][1] = blue;
solutionArray[3][2] = white;
solutionArray[3][3] = white;
solutionArray[3][4] = blue;
solutionArray[3][5] = blue;
solutionArray[4][0] = blue;
solutionArray[4][1] = blue;
solutionArray[4][2] = white;
solutionArray[4][3] = blue;
solutionArray[4][4] = white;
solutionArray[4][5] = white;
solutionArray[5][0] = blue;
solutionArray[5][1] = white;
solutionArray[5][2] = blue;
solutionArray[5][3] = white;
solutionArray[5][4] = blue;
solutionArray[5][5] = white;
//USER ARRAY
userArray[0][0] = blue;
userArray[0][1] = grey;
userArray[0][2] = grey;
userArray[0][3] = grey;
userArray[0][4] = grey;
userArray[0][5] = blue;
userArray[1][0] = grey;
userArray[1][1] = blue;
userArray[1][2] = grey;
userArray[1][3] = grey;
userArray[1][4] = grey;
userArray[1][5] = white;
userArray[2][0] = grey;
userArray[2][1] = grey;
userArray[2][2] = blue;
userArray[2][3] = grey;
userArray[2][4] = white;
userArray[2][5] = grey;
userArray[3][0] = grey;
userArray[3][1] = grey;
userArray[3][2] = grey;
userArray[3][3] = grey;
userArray[3][4] = grey;
userArray[3][5] = grey;
userArray[4][0] = grey;
userArray[4][1] = grey;
userArray[4][2] = white;
userArray[4][3] = grey;
userArray[4][4] = grey;
userArray[4][5] = white;
userArray[5][0] = grey;
userArray[5][1] = grey;
userArray[5][2] = grey;
userArray[5][3] = grey;
userArray[5][4] = blue;
userArray[5][5] = white;
var x = document.createElement("TABLE");
x.setAttribute("id", "gridTable");
document.body.appendChild(x);
for (i = 0; i < 6; i++) {
//output the row tag
var y = document.createElement("TR");
y.setAttribute("id", "row" + i);
document.getElementById("gridTable").appendChild(y)
for (j = 0; j < userArray.length; j++) {
///output the td tag
var z = document.createElement("TD");
if (userArray[i][j] == blue) {
z.setAttribute("class", "blue");
} else if (userArray[i][j] == white) {
z.setAttribute("class", "white");
} else if (userArray[i][j] == grey) {
z.setAttribute("class", "grey");
}
document.getElementById("row" + i).appendChild(z);
}
}
document.querySelector("#gridTable").addEventListener("click", function(event) {
if(event.target.classList.contains("blue")){
event.target.className = 'grey';
}else if(event.target.classList.contains("grey")){
event.target.className = 'white'
}else if(event.target.classList.contains("white")){
event.target.className = 'blue'
}
});
.blue {
background-color: blue;
}
.grey{
background-color:grey;
}
.white{
background-color:white;
}
td {
text-align: center;
border: 1px solid black;
padding: 3px;
height: 50px;
width: 50px;
}
table {
border-collapse: collapse;
}
table td {
cursor: pointer;
}