I’m working on my Simon Game and was wondering if it is possible to add a specific event listener to a button based it’s innerText?
For example. I have a button saying “START GAME”. It gets clicked, a countdown from 3, 2, 1 occurs.
Then I want the button to switch to “RESTART” and I would like the functionality for the restart function to be set. Here’s my code thus far…
startGame.addEventListener('click', () => {
startGame.style.pointerEvents = "none";
let time = 4;
let countDown = () => {
time--;
startGame.innerText = time;
if (time < 1) {
startGame.innerText = "GO!";
clearInterval(counter);
setTimeout(() => {
startGame.innerText = "RESTART";
// do i detach the event handler and write a new one here?
}, 2000);
}
};
const counter = setInterval(countDown, 1000);
});