let body = document.querySelector("body")
let container = document.querySelector("#container")
//Accessing HTML Elements
let inputArr = []
for (let rowCount = 0; rowCount < 6; rowCount++) {
let row = []
inputArr.push(row)
for (let i = 0; i < 5; i++) {
let space = document.createElement("input");
container.appendChild(space)
row.push(space);
space.classList.add("square")
}
}
//for loops that make the grid of squares for the wordle, and store them inside a 2d array
let wordSet = ["panic", "knobs", "swain", "dupes", "venom", "great", "carom", "soare"]
let num = Math.floor(Math.random()*8)
let word = wordSet[num]
console.log(word)
for (let rowVal = 0; rowVal < 6; rowVal++) {
for (let col = 0; col < 5; col++) {
if (inputArr[rowVal][col].value instanceof String && inputArr[rowVal][col] == word[col]) {
inputArr[rowVal][col].style.backgroundColor = "green"
}
}
}
The last part of the code essentially checks whether the input value of a square is equal to a string, and if the value matches a letter in the word. If these two things are true, then the square is supposed to change to green.
Is there another way to achieve the task of checking whether a letter is correct or not that works?