-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (45 loc) · 1.49 KB
/
Copy pathmain.js
File metadata and controls
52 lines (45 loc) · 1.49 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
// To play the click game
var button = document.querySelector('.button');
var click = 0; // number of clicks
var highScore = 0; // highscore at a particular time
var timeout = 11;
//timer
function count() {
document.querySelector('.start').addEventListener('click', () => {
document.querySelector('.start').innerHTML = "Restart?";
// Storing highscore
if (timeout === 0) {
document.querySelector('.timer').innerHTML = "Do better boi!";
if (click > highScore)
highScore = click - 1;
}
// Setting timer operations
document.querySelector('.score').innerHTML = highScore;
timeout = 11;
click = 0;
document.querySelector('.clicks').innerHTML = click;
//start timer
document.querySelector('.timer').innerHTML = "Your time starts now";
var timer = setInterval(() => {
document.querySelector('.start').addEventListener('click', () => {
clearInterval(timer);
});
timeout--;
// resetting timer
document.querySelector('.timer').innerHTML = "Time left: " + timeout;
if (timeout === 0) {
clearInterval(timer);
document.querySelector('.timer').innerHTML = "Time up!";
document.querySelector('.start').innerHTML = "Retry";
}
}, 1000);
});
}
// Calling count function
count();
// If extra
document.querySelector('.button').addEventListener('click', () => {
if (timeout > 0 && timeout != 11)
document.querySelector('.clicks').innerHTML = click++;
//if (timeout === 0)
});