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

409
Vistas
I'm trying to make a wordle clone, but can't get it to function properly. Is there anything I can do to make it work?
let body = document.querySelector("body")
let container = document.querySelector("#container")
let enter = document.querySelector("#enter")



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")
  }
}


let wordSet = ["panic", "knobs", "swain", "dupes", "venom", "great", "carom", "soare"]

let num = Math.floor(Math.random()*8)
let word = wordSet[num]
console.log(word)

enter.addEventListener("click", () => {

  for (let rowVal = 0; rowVal < 6; rowVal++) {
  for (let col = 0; col < 5; col++) {
    let current = inputArr[rowVal][col].value
    
    if (current === "" || inputArr[rowVal][col].style.backgroundColor !== "darkgray") {
      rowVal++
    }

    

      if (current == word[col]) {
      inputArr[rowVal][col].style.backgroundColor = "green" 
    }

       if (current !== word[col] && word.indexOf(current)) {
        inputArr[rowVal][col].style.backgroundColor = "yellow"
      }

       if (current !== word[col] && word.indexOf(current) == false) {
        inputArr[rowVal][col].style.backgroundColor = "white"
      }

    
    
  }
}
  
})

Whenever I type in some letters into the spaces and press the enter button, the colors of squares in other rows change, and it seems to be in a diagonal fashion. I tried messing around with the if statements, and changing them to else if statements, and I feel like that could have to do with why the wordle clone isn't working, but I'm still not entirely sure.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think the problem is here:

 word.indexOf(current) == false

indexOf returns the index or -1.

-1 == false // false
about 4 years ago · Juan Pablo Isaza Denunciar
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