Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda