Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

329
Views
I'm trying to make a wordle clone, but for some reason my congratulations message isn't displayed when the user gets the word right. How can I fix it?
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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!