Display solution once game is complete

This commit is contained in:
Arne Keller 2022-02-23 15:35:32 +01:00
parent e4d9c46420
commit 432fc38bf5
2 changed files with 19 additions and 2 deletions

View File

@ -23,6 +23,14 @@ body.wide {
gap: 2em;
}
.solution {
text-align: center;
width: inherit;
display: block;
font-size: x-large;
display: none;
}
.row {
margin-top: 0;
margin-bottom: 0;

View File

@ -55,9 +55,13 @@ const MAX_GUESSES = 9;
const guessed = [];
let input = "";
const data = [];
const solutions = [];
const done = [false, false, false, false];
function gameOver() {
for (const el of solutions) {
el.style.display = "block";
}
const NUMBERS = "0⃣1⃣2⃣3⃣4⃣5⃣6⃣7⃣8⃣9⃣";
const ANY = "⬜";
const POSITION = "🟨";
@ -321,16 +325,21 @@ for (let i = 0; i < 3; i++) {
function createGameGrid(container) {
for (let pos = 0; pos < 4; pos++) {
container.appendChild(createWordle());
container.appendChild(createWordle(chosenWords[pos]));
}
}
function createWordle() {
function createWordle(word) {
const x = document.createElement("div");
x.className = "wordle";
for (let i = 0; i < MAX_GUESSES; i++) {
x.appendChild(createRow(data));
}
const solution = document.createElement("span");
solution.className = "solution";
solution.innerText = word;
x.appendChild(solution);
solutions.push(solution);
return x;
}