Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

292
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda