-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-roulette-cards2.html
More file actions
59 lines (47 loc) · 1.36 KB
/
code-roulette-cards2.html
File metadata and controls
59 lines (47 loc) · 1.36 KB
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
50
51
52
53
54
55
56
57
58
59
<script>
function Deck() {
this.cards = [];
this.count = function() {
return this.cards.length;
}
this.init = function() {
for (s = 1; s <= 4; s++){
for (r = 1; r <= 13; r++) {
this.cards.push(new Card(r, s))
}
}
}
}
function Card(rank, suit) {
this.rank = rank;
this.suit = suit;
this.showRank = function() {
var ranks = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King"]
return ranks[this.rank - 1]
}
this.show = function() {
var suits = ["Hearts", "Spades", "Diamonds", "Clubs"]
return this.showRank() + " of " + suits[this.suit - 1]
}
}
function Game() {
deck = new Deck();
deck.init();
this.p1 = deal();
guess = prompt("Welcome to a Code Roulette (Card Version). Please guess the card rank and suit. If you guess correct you win $1 million. If you guess wrong you die.");
alert("The card drawn was " + this.p1.show());
if(guess == this.p1.show()) {
alert("That is correct. Congratulations. You win $1 million.");
}
else {
alert("Sorry, you die.");
}
function deal() {
var index = Math.floor(Math.random() * deck.cards.length)
var selectedCard = deck.cards[index];
deck.cards.splice(index, 1);
return selectedCard;
}
}
codeRouletteCards = new Game();
</script>