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; gap: 2em;
} }
.solution {
text-align: center;
width: inherit;
display: block;
font-size: x-large;
display: none;
}
.row { .row {
margin-top: 0; margin-top: 0;
margin-bottom: 0; margin-bottom: 0;

View File

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