I have been developing a memory game and it working perfect. I wanted to add a life function in the game where after each wrong match , the player loses one of the hearts on the screen . I have attached the image below:
What i have achieved till now is, when i make the first unmatch, the life decrease by one but after that there is no decrease in life. I have attached the snippet code below :
function unmatched() {
openedCards[0].classList.add("unmatched");
openedCards[1].classList.add("unmatched");
life();
}
function life(){
for(let i=0; i<5; i++) {
if(i=4) {
starElementsArray[i].style.opacity = 0.1;
}
}
}
In the above code, when the function unmatch is executed it checks for the life function where the life is inside the array and i m reducing the opacity of one heart. when i make the first unmatch, it works , but after that I could not reduce the opacity of other hearts one by one. I m kin of stuck in this iteration part. Can someone help me fix this .
Aucun commentaire:
Enregistrer un commentaire