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

Function checkForMatch

MEMORY/index.js:75–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73
74 //check for matches
75 function checkForMatch() {
76 const cards = document.querySelectorAll('img')
77 const optionOneId = cardsChosenId[0]
78 const optionTwoId = cardsChosenId[1]
79
80 if(optionOneId == optionTwoId) {
81 cards[optionOneId].setAttribute('src', 'images/blank.png')
82 cards[optionTwoId].setAttribute('src', 'images/blank.png')
83 alert('You have clicked the same image!')
84 }
85 else if (cardsChosen[0] === cardsChosen[1]) {
86 alert('You found a match')
87 cards[optionOneId].setAttribute('src', 'images/white.png')
88 cards[optionTwoId].setAttribute('src', 'images/white.png')
89 cards[optionOneId].removeEventListener('click', flipCard)
90 cards[optionTwoId].removeEventListener('click', flipCard)
91 cardsWon.push(cardsChosen)
92 } else {
93 cards[optionOneId].setAttribute('src', 'images/blank.png')
94 cards[optionTwoId].setAttribute('src', 'images/blank.png')
95 alert('Sorry, try again')
96 }
97 cardsChosen = []
98 cardsChosenId = []
99 resultDisplay.textContent = cardsWon.length
100 if (cardsWon.length === cardArray.length/2) {
101 resultDisplay.textContent = 'Congratulations! You found them all!'
102 }
103 }
104
105 //flip your card
106 function flipCard() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected