Skip to content
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
7 changes: 4 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<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 THE STYLES HERE -->
<link rel="stylesheet" href="styles/style.css">

</head>
<body>
<div>
Expand All @@ -17,7 +18,7 @@ <h2>Score</h2>
<p>Pairs guessed: <span id="pairs-guessed">0</span></p>
</div>
<div id="memory-board"></div>

<!-- LINK THE JAVASCRIPT FILES HERE (keep in mind that the order in which you link them MATTERS) -->
<script type="text/javascript" src="src/index.js"></script>
<script type="text/javascript" src="src/memory.js"></script>
</body>
</html>
24 changes: 19 additions & 5 deletions src/memory.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
class MemoryGame {
constructor(cards) {
this.cards = cards;
// add the rest of the class properties here
this.pickedCards = [];
this.pairsClicked = 0;
this.pairsGuessed = 0;
this.shuffleCards();
}

shuffleCards() {
// ... write your code here
if (!this.cards) return undefined;

for (let i = this.cards.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[this.cards[i], this.cards[j]] = [this.cards[j], this.cards[i]];
}
}

checkIfPair(card1, card2) {
// ... write your code here
this.pairsClicked++;
if (card1 === card2) {
this.pairsGuessed++;
return true;
} else {
return false;
}
}

checkIfFinished() {
// ... write your code here
return this.pairsGuessed === this.cards.length / 2;
}
}
}