I’m creating a Word Search Game and I’m trying to figure out how to generate my chosen words onto the HTML grid I created. Somebody already helped me find a way to randomly generate the words into a row and column, but it generates the whole word into a cell, whereas I need each letter of the word to be randomly placed in an individual cell (If that makes sense).
const myWords = ["LOL", "HEY", "TOYS", "YES", "SIR", "JOY"];
for (let i = 0; i <myWords.length; i++)
{
const randomIndex = length => Math.floor(Math.random()*length);
const table = document.querySelector('table');
const randomRow = table.rows[randomIndex(myWords.length)];
const randomCell = randomRow.cells[randomIndex(myWords.length)];
const randomWord = myWords[Math.floor(Math.random() * myWords.length)];
randomCell.innerText = randomWord;
}
I planned on having the words horizontal, vertical and diagonal. I tried searching through Stack Overflow and Github, with no success. Can someone help?