-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-solved.js
More file actions
45 lines (35 loc) · 813 Bytes
/
script-solved.js
File metadata and controls
45 lines (35 loc) · 813 Bytes
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
const stats = document.querySelector('.stats');
const btnStart = document.querySelector('button[name=start]');
const btnClick = document.querySelector('button[name=click]');
const winScore = 10;
let count = 0;
btnStart.addEventListener('click', () => {
start();
});
btnClick.addEventListener('click', () => {
count++;
stats.textContent = count;
});
const start = () => {
count = 0;
stats.textContent = count;
btnClick.removeAttribute('disabled');
startCounting();
}
const startCounting = () => {
setTimeout(() => {
if(isWin()) {
stats.textContent = 'You Won!';
} else {
stats.textContent = 'You Lost!';
}
btnClick.setAttribute('disabled', true);
}, 2000);
}
const isWin = () => {
if(count < winScore) {
return false;
} else {
return true;
}
}