forked from breatheco-de/exercise-random-card
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (64 loc) · 2.04 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
window.onload = function() {
let flipEl = document.querySelector('.flip');
let suiteEls = document.querySelectorAll('.suite');
let numberEl = document.querySelector('.number');
let countdownEl = document.querySelector('.countdown');
let progressEl = document.getElementById('progressBar');
flipEl.addEventListener('click', flipIt);
// flip card
function flipIt() {
const suites = ['heart', 'spade', 'club', 'diamond'];
const numNum = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'];
// function ranNum(min, max) {
// return Math.floor(Math.random() * (max - min + 1) + min);
// }
// const newNum = ranNum(2, 10);
// numberEl.innerHTML = newNum;
function getRandomItem(arr) {
const randomIndex = Math.floor(Math.random() * arr.length);
const item = arr[randomIndex];
return item;
}
const result = getRandomItem(suites);
const ranNum = getRandomItem(numNum);
numberEl.innerHTML = ranNum;
for (const suiteEl of suiteEls) {
suiteEl.src = `img/${result}.svg`;
}
if (result == 'heart' || result == 'diamond') {
numberEl.classList.add('red');
console.log('red');
}
else {
numberEl.classList.remove('red');
console.log('black');
}
}
// timer
let timeleft = 10;
let downloadTime = setInterval(function() {
if (timeleft <= 10 && timeleft > -1) {
progressEl.value = 10 - timeleft;
timeleft -= 1;
countdownEl.innerHTML = timeleft + 1;
console.log('c');
}
if (timeleft <= -1) {
flipIt();
clearInterval(downloadTime);
timeleft -= 1;
progressEl.value = 0;
countdownEl.innerHTML = '10';
console.log('a');
}
}, 1000);
// change dimensions
let widthEl = document.getElementById('width');
let heightEl = document.getElementById('height');
let submitEl = document.getElementById('submit');
submitEl.addEventListener('click', changeWidth);
function changeWidth() {
document.querySelector('.card').style.width = widthEl.value + 'px';
document.querySelector('.card').style.height = heightEl.value + 'px';
}
};