-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·39 lines (30 loc) · 1.15 KB
/
index.js
File metadata and controls
executable file
·39 lines (30 loc) · 1.15 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
import Card from "./components/card.js"; // imports the Card class from card.js file
import {Score} from "./components/score.js";
customElements.define("my-card", Card);
customElements.define("my-score", Score);
const cardArry = ["square",
"square",
"circle",
"circle",
"triangle",
"triangle",
"pentagone",
"pentagone",
"free"
];
const r1 = document.getElementById("board");
// dealing cards
for(let i=0; i<9; i++) {
// creates a random number [0,1)
let randnum = Math.random();
// contains the number between 0 and cardArry.length and makes it an integer
let randindx = Math.floor(randnum * cardArry.length);
// creates a card element with image from cardArry
const card = document.createElement("my-card");
// creates custom card element
card.setAttribute("face", `./images/${cardArry[randindx]}.svg`);
card.setAttribute("back", "./images/backingBlue.svg");
r1.appendChild(card);
// removes 1 item from cardArry
cardArry.splice(randindx, 1);
}