-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.js
49 lines (43 loc) · 832 Bytes
/
card.js
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
44
45
46
47
48
49
class Card {
constructor(suit, value) {
this.suit = suit;
this.value = value;
}
toString() {
function jsUcfirst(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var ret = '';
var value = this.value;
var suit = jsUcfirst(this.suit);
if (value === 1) {
ret = 'Ace'
}
else if (value === 11) {
ret = 'Jack'
}
else if (value === 12) {
ret = 'Queen'
}
else if (value === 13) {
ret = 'King'
}
else {
ret = value;
}
return ret + ' of ' + suit;
}
// PERSISTENCE FUNCTIONS
// =====================
fromObject(object) {
this.value = object.value;
this.suit = object.suit;
}
toObject() {
return {
value: this.value,
suit: this.suit
};
}
}
module.exports = Card;