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

298
Visualizações
I'm trying to make a wordle clone, but can't get a square to turn green if the letter inside of it matches a letter in the word. How can I do this?
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?

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