MCPcopy Create free account
hub / github.com/codemistic/Web-Development / checkMatch

Function checkMatch

Memory Game/app.js:72–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70createBoard();
71
72function checkMatch() {
73 const cards = document.querySelectorAll("img");
74 const optionOneId = cardChosenId[0];
75 const optionTwoId = cardChosenId[1]
76
77
78 if(optionOneId == optionTwoId){
79
80 cards[optionOneId].setAttribute('src', 'img/blank.png')
81 cards[optionTwoId].setAttribute('src', 'img/blank.png')
82 alert('you have clicked the same image!');
83 }
84 if (cardChosen[0] == cardChosen[1]) {
85 alert("you found a match");
86 cards[optionOneId].setAttribute('src', 'img/white.png');
87 cards[optionTwoId].setAttribute('src', 'img/white.png');
88 cards[optionOneId].removeEventListener('click',flipCard);
89 cards[optionTwoId].removeEventListener('click',flipCard);
90 cardWon.push(cardChosen);
91 }else{
92 cards[optionOneId].setAttribute('src', 'img/blank.png');
93 cards[optionTwoId].setAttribute('src','img/blank.png');
94 alert('sorry try again');
95 }
96
97
98 resultDisplay.textContent = cardWon.length
99 cardChosen = [];
100 cardChosenId = [];
101
102if(cardWon.length == cardArray.length/2){
103 resultDisplay.textContent = "Cogratulation you found them all!";
104}
105}
106function flipCard() {
107
108 const cardId = this.getAttribute("data-id");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected