-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.js
More file actions
55 lines (51 loc) · 1.23 KB
/
scripts.js
File metadata and controls
55 lines (51 loc) · 1.23 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
const TOTAL = 24;
let cards, current;
const excludeFirst = ['01.jpg', '11.jpg', '12.jpg', '19.jpg'];
init();
console.log(cards)
function init() {
current = 0;
cards = prepareCards(TOTAL);
while (true) {
shuffle(cards);
if (!excludeFirst.includes(cards[0])){
break;
}
}
change();
}
function prepareCards(num) {
let cards = []
for (let i = 1; i <= num; i++) {
cards.push(i.toString().padStart(2, '0') + '.jpg')
}
return cards
}
function shuffle(cards) {
let len = cards.length;
let index, temp
while (len > 0) {
index = Math.floor(Math.random() * len)
temp = cards[len - 1]
cards[len - 1] = cards[index]
cards[index] = temp
len--
}
}
function change() {
console.log('current', current);
if (current === TOTAL) {
init();
return
}
if (current === 0) {
// let tipDom = document.getElementById('tip');
// tipDom.classList.remove("hidden")
} else {
let tipDom = document.getElementById('tip');
tipDom.classList.add("hidden")
}
let imgDom = document.getElementById('img');
imgDom.setAttribute('src', `./images/${cards[current]}`);
current++
}