Skip to content

Commit

Permalink
Merge pull request #43 from SimonStnn/feature/history-section
Browse files Browse the repository at this point in the history
Feature/history section
  • Loading branch information
C-o-m-o-n authored Jan 4, 2024
2 parents 7ca07dd + eb2c7b2 commit 4abe083
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions resources/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function checkGuess() {

checkGuessButton.addEventListener('click', () => {
checkGuess();
updateHistory();
});

function resetGame() {
Expand Down Expand Up @@ -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()
})

0 comments on commit 4abe083

Please sign in to comment.