-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathmemory.js
More file actions
43 lines (38 loc) · 863 Bytes
/
memory.js
File metadata and controls
43 lines (38 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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() {
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
}
}