Currently, I am in the process of developing a Word Search Game and one obstacle I am facing is how to display my selected words on the HTML grid that I have created. While someone did assist me with randomly generating the words into rows and columns, the issue is that it places the entire word in a single cell, when what I actually need is for each letter of the word to be distributed randomly among individual cells (hopefully 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 had initially planned on having the words aligned horizontally, vertically, and diagonally but my efforts to find a solution on platforms like Stack Overflow and Github have been fruitless. Is there anyone out there who can provide some guidance?