-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (28 loc) · 826 Bytes
/
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
const cards = document.querySelectorAll(".card")
cards.forEach(addCardElements)
function addCardElements(card) {
const value = card.dataset.value
// const suit = card.dataset.suit
const valueAsNumber = parseInt(value)
if (isNaN(valueAsNumber)) {
card.append(createPip())
} else {
for (let i = 0; i < valueAsNumber; i++){
card.append(createPip())
}
}
card.append(createCornerNumber("top", value))
card.append(createCornerNumber("bottom", value))
}
function createCornerNumber(position, value) {
const corner = document.createElement("div")
corner.textContent = value
corner.classList.add("corner-number")
corner.classList.add(position)
return corner
}
function createPip() {
const pip = document.createElement("div")
pip.classList.add("pip")
return pip
}