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

408
Views
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 answers
Answer question

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 Report
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!