Skip to content

Instantly share code, notes, and snippets.

@arelthia
Created April 23, 2022 23:39
Show Gist options
  • Save arelthia/97e0b17439b8a8dfb08dd48c1e5547f8 to your computer and use it in GitHub Desktop.
Save arelthia/97e0b17439b8a8dfb08dd48c1e5547f8 to your computer and use it in GitHub Desktop.
Wordle Grid
let grid = document.querySelector("#game");
// the number of guesses
let guessesAllowed = 4;
// the length of the word
let wordLength = 3;
// generate 3 rows
let fragement = document.createDocumentFragment();
let generateGrid = () => {
// where each row contains 3 columns
Array.from({length: guessesAllowed}).forEach(() => {
let row = document.createElement('div');
row.classList.add('row');
Array.from({length: wordLength}).forEach(() =>{
let tile = document.createElement('div');
tile.classList.add('tile');
row.appendChild(tile);
});
fragement.appendChild(row);
});
//append to the grid
grid.append(fragement);
}
generateGrid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment