rfpotrero / hangman

0 stars 1 forks source link

Code refactoring to improve readability and fix bug introduced in Issue 23. #24

Closed rfpotrero closed 2 years ago

rfpotrero commented 2 years ago
for (let button of buttons) {
    button.addEventListener("click", function () {
        let sourceType = this.innerHTML;
        newGame(sourceType);
    });
}
rfpotrero commented 2 years ago

Add id="category-btn" to HTML button element.

rfpotrero commented 2 years ago

The issue 23 added a else statement to catch any unrecognised category. This introduced a bug in the code since the event listener above was attached to all the button types. The Play again buttons were triggering the alert error handling.

rfpotrero commented 2 years ago

// The below create event listener for clicks in the category buttons. document.addEventListener("DOMContentLoaded", function () {

document.getElementById("draw-graphic").innerHTML = ` <img style="height:100%;width:100%;" src="assets/images/48361197.jpeg" alt="Drawn of a hangman" />`;

let buttonCate = document.getElementById("category-btn");
buttonCate.addEventListener("click",gameInit);

});