let body = document.querySelector("body")
let container = document.querySelector("#container")
let enter = document.querySelector("#enter")
let restart = document.querySelector("#restart")
let inputArr = []
for (let rowCount = 0; rowCount < 6; rowCount++) {
let row = []
inputArr.push(row)
for (let column = 0; column < 5; column++) {
let space = document.createElement("input")
space.classList.add("square")
container.appendChild(space)
row.push(space)
}
}
function wordle() {
let wordSet = ["panic", "dupes", "crate", "great", "soare", "avoid", "knobs", "venom"]
let correct = []
let enteredLetters = []
let num = Math.floor(Math.random()*wordSet.length)
let word = wordSet[num]
console.log(word)
let enterClicks = -1
enter.addEventListener("click", () => {
enterClicks++
for (let rowVal = 0; rowVal < 6; rowVal++) {
for (let col = 0; col<5; col++) {
let square = inputArr[rowVal][col]
let current = square.value
if (current == word[col]) {
square.style.backgroundColor = "green"
correct.push(current)
}
if (current !== word[col] && word.indexOf(current) !== -1) {
square.style.backgroundColor = "yellow"
}
if (current == "") {
current.disabled = false
for (let z = 0; z < 5; z++) {
inputArr[rowVal][z].style.backgroundColor = "white"
}
}
if (current !== word[col] && word.indexOf(current) == -1) {
square.style.backgroundColor = "darkgray"
}
}
}
for (let c = 0; c < 6; c++) {
inputArr[enterClicks][c].disabled = true
enteredLetters.push(inputArr[enterClicks][c].value)
}
let foundLetters = []
for (let w = 0; w < 5; w++) {
if (correct.indexOf(word[w]) !== -1) {
foundLetters.push(word[w])
}
}
if (foundLetters.length == 5) {
window.alert("Congratulations! You Beat Wordle 2.0! Click the 'PLAY AGAIN' button to start a new round.")
}
})
}
wordle()
restart.onclick = () => {
location.reload()
}
By the way, the foundLetters array basically stores the characters that match in both the word and the correct array. Everything else seems to be working perfectly fine, but it's just the last bit of code, starting at the declaration of foundLetters until the end, that doesn't seem to work as it should.