-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathscript.js
43 lines (42 loc) · 1.11 KB
/
script.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
function deckBuilder() {
const values = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
const suits = ["Hearts", "Diamonds", "Spades", "Clubs"];
const cards = [];
for (let s = 0; s < suits.length; s++) {
for (let v = 0; v < values.length; v++) {
const value = values[v];
const suit = suits[s];
cards.push({ value, suit });
}
}
return cards;
}
function randomCard(cards) {
const random = Math.floor(Math.random() * 51);
const cardValue = cards[random].value;
const cardSuit = cards[random].suit;
let entity;
cardSuit === "Diamonds"
? (entity = "♦")
: (entity = "&" + cardSuit.toLowerCase() + ";");
const card = document.createElement("div");
card.classList.add("card", cardSuit.toLowerCase());
card.innerHTML = '<span class="card-value-suit top">' + cardValue + entity + "</span>" + '<span class="card-suit">' + entity + "</span>" + '<span class="card-value-suit bot">' + cardValue + entity + "</span>";
document.body.appendChild(card);
}
const cards = deckBuilder();
randomCard(cards);