I've been experimenting with creating a hangman game using JavaScript and HTML. However, I'm facing an issue where clicking on a letter doesn't replace the "_" placeholder.
var myList=["Computer","Algorithm","Software","Programming","Developer"];
var n;
var star="_";
console.log(myList)
computer=myList[Math.floor(Math.random() * myList.length)];
console.log(computer);
var word= document.getElementById("word").innerHTML=star.repeat(computer.length);
var letter=document.getElementsByClassName("col")
function myFunction(){
n=word.replace(star,letter);
};
for (var i=0; i<letter.length;i++){
letter[i].addEventListener("click",myFunction());
}
myFunction();
The "letter" elements represent the alphabet in this case (they are not buttons but divs). The "word" element is an empty div that should display "-" characters, which should be replaced by the clicked letters.