()
| 70 | createBoard(); |
| 71 | |
| 72 | function 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 | |
| 102 | if(cardWon.length == cardArray.length/2){ |
| 103 | resultDisplay.textContent = "Cogratulation you found them all!"; |
| 104 | } |
| 105 | } |
| 106 | function flipCard() { |
| 107 | |
| 108 | const cardId = this.getAttribute("data-id"); |
nothing calls this directly
no outgoing calls
no test coverage detected