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

288
Views
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
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!