-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.js
More file actions
40 lines (37 loc) · 865 Bytes
/
Deck.js
File metadata and controls
40 lines (37 loc) · 865 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
class Card{
constructor(number,suit){
this.number = number;
this.suit = suit;
this.value = this.number + this.suit
}
}
class Deck{
constructor(){
this.deck = [];
this.newDeck();
}
newDeck(){
var suit = ['Diamonds','Spades','Hearts','Clover'];
var numbers = ['A','1','2','3','4','5','6','7','8','9','10','J','Q','K'];
for (var i = 0; i < suit.length ; i ++){
for (var j = 0; j < numbers.length ; j++){
this.deck.push(new Card(numbers[j],suit[i]));
}
}
}
clear(){
while (this.deck.length){
this.deck.pop();
}
}
draw(){
return this.deck.pop();
}
shuffle(){
this.deck.sort(() => Math.random() > 0.5 ? 1 : -1);
}
}
var deck = new Deck();
deck.clear();
deck.newDeck();
console.log(deck)