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

Michael Diaz WD PT MAD 9TH SEP #1966

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions src/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@ class MemoryGame {
constructor(cards) {
this.cards = cards;
// add the rest of the class properties here
this.pickedCards = []; // Array to store the cards selected by the user
this.pairsClicked = 0; // Number of pairs clicked
this.pairsGuessed = 0; // Number of pairs guessed correctly
this.shuffleCards(); // Shuffle cards when a new game is created
}

shuffleCards() {
// ... write your code here
// Fisher-Yates Shuffle algorithm
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]]; // Swap cards
}
}

checkIfPair(card1, card2) {
// ... write your code here
this.pairsClicked++; // Increment pairs clicked

// Check if the two selected cards are the same
if (card1 === card2) {
this.pairsGuessed++; // Increment pairs guessed
return true; // Return true if they match
} else {
return false; // Return false if they do not match
}
}

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