Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solved lab #1956

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Superhero Memory Game</title>
<link rel="stylesheet" href="styles/style.css">
<!-- LINK THE STYLES HERE -->
</head>
<body>
Expand All @@ -18,6 +19,9 @@ <h2>Score</h2>
</div>
<div id="memory-board"></div>

<script src="src/memory.js"></script>
<script src="src/index.js"></script>

<!-- LINK THE JAVASCRIPT FILES HERE (keep in mind that the order in which you link them MATTERS) -->
</body>
</html>
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,27 @@ window.addEventListener('load', (event) => {
<div class="front" style="background: url(img/${pic.img}) no-repeat"></div>
</div>
`;
});
})

})

// Add all the divs to the HTML
document.querySelector('#memory-board').innerHTML = html;

// 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}`);
});
});
});


27 changes: 26 additions & 1 deletion src/memory.js
Original file line number Diff line number Diff line change
@@ -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
}
}