diff --git a/resources/js/index.js b/resources/js/index.js index 68effd0..30a7e42 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -175,6 +175,7 @@ function checkGuess() { checkGuessButton.addEventListener('click', () => { checkGuess(); + updateHistory(); }); function resetGame() { @@ -298,22 +299,29 @@ stopBgMusicButton.addEventListener('click', () => { backgroundMusicPlayer.playRandomTrack(); }); +function updateHistory(){ + const history = document.getElementById('history-scores') + while (history.firstChild) { + history.removeChild(history.lastChild); + } + for(const item of historyManager.history){ + const div = document.createElement('div') + div.classList.add('history-score') + + const attempts = document.createElement('span') + attempts.innerText = `Attempts: ${item.attempts}` + const score = document.createElement('span') + score.innerText = `Score: ${item.score}` + const timer = document.createElement('span') + timer.innerText = `Time: ${item.timer}` + + div.appendChild(score) + div.appendChild(attempts) + div.appendChild(timer) + history.appendChild(div) + } +} + window.addEventListener("DOMContentLoaded", ()=>{ - console.log(historyManager.history); - for(const item of historyManager.history){ - const div = document.createElement('div') - div.classList.add('history-score') - - const attempts = document.createElement('span') - attempts.innerText = `Attempts: ${item.attempts}` - const score = document.createElement('span') - score.innerText = `Score: ${item.score}` - const timer = document.createElement('span') - timer.innerText = `Time: ${item.timer}` - - div.appendChild(score) - div.appendChild(attempts) - div.appendChild(timer) - document.getElementById('history-scores').appendChild(div) - } + updateHistory() })