diff --git a/index.html b/index.html index 9386faaf4..65a66b3c2 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@ Superhero Memory Game + @@ -18,6 +19,9 @@

Score

+ + + diff --git a/src/index.js b/src/index.js index 37f3a672d..778a31b79 100644 --- a/src/index.js +++ b/src/index.js @@ -36,7 +36,9 @@ window.addEventListener('load', (event) => {
`; - }); + }) + +}) // Add all the divs to the HTML document.querySelector('#memory-board').innerHTML = html; @@ -44,8 +46,17 @@ window.addEventListener('load', (event) => { // Bind the click event of each element to a function document.querySelectorAll('.card').forEach((card) => { card.addEventListener('click', () => { + + card.classList.toggle('turned'); + /* memoryGame.checkIfPair() + if(memoryGame.checkIfPair()){ */ + + + }) + + // TODO: write some code here console.log(`Card clicked: ${card}`); }); - }); -}); + + diff --git a/src/memory.js b/src/memory.js index f6644827e..45bb9682e 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,18 +1,43 @@ class MemoryGame { constructor(cards) { this.cards = cards; + this.pickedCards = []; + this.pairsClicked = 0; + this.pairsGuessed = 0; + // add the rest of the class properties here } shuffleCards() { - // ... write your code here + if(!this.cards){return undefined} + else { + for (let i = this.cards.length - 1; i > 0; i--) { + let j = Math.floor(Math.random() * (i + 1)); + [this.cards[i], this.cards[j]] = [this.cards[j], this.cards[i]] + } + return this.cards + } } checkIfPair(card1, card2) { + if(card1 === card2){ + this.pairsClicked +=1; + this.pairsGuessed +=1; + return true + } + else { + this.pairsClicked +=1 + return false + } // ... write your code here } checkIfFinished() { + if (this.pairsGuessed != this.cards.length/2){ + return false + }else + return true + // ... write your code here } }