Skip to content

Commit

Permalink
Event listener for submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
deponte-designer committed Dec 5, 2023
1 parent d587336 commit d7187dd
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion assets/js/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,33 @@ function endQuiz() {
choicesElement.innerHTML = '';
endScreenElement.classList.remove('hide');
finalScoreElement.textContent = time;
}
};

// Event listener for start button
startButton.addEventListener('click', startQuiz);

// Event listener for submit button
submitButton.addEventListener("click", function () {
const initials = initialsInput.value.trim();
if (initials !== "") {
// Save initials and score to local storage
const scoreData = {
initials: initials,
score: time,
};

// Retrieve existing highscores or initialize an empty array
const highscores = JSON.parse(localStorage.getItem("highscores")) || [];

// Add the new score data
highscores.push(scoreData);

// Save the updated highscores to local storage
localStorage.setItem("highscores", JSON.stringify(highscores));

// Redirect or do any additional action as needed
console.log("Score saved:", scoreData);
}

window.location.href = 'highscores.html';
});

0 comments on commit d7187dd

Please sign in to comment.