-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (70 loc) · 1.89 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const referenceText = document.getElementById("referenceText")
const inputVal = document.getElementById("inputVal")
inputVal.addEventListener('input', () => {
const letters_array = referenceText.querySelectorAll('span')
const arrayVal = inputVal.value.split('')
let tempVar = true
letters_array.forEach((characterSpan, index) => {
const character = arrayVal[index]
if (character == null)
// IF IT DOESN'T EXIST
{
characterSpan.classList.remove('correct')
characterSpan.classList.remove('incorrect')
tempVar = false
} else if (character === characterSpan.innerText)
// IF IT IS CORRECT
{
characterSpan.classList.add('correct')
characterSpan.classList.remove('incorrect')
} else
// IF IT IS WRONG
{
characterSpan.classList.remove('correct')
characterSpan.classList.add('incorrect')
tempVar = false
}
startTimer()
})
if (tempVar) {stopTimer()}
})
// TIMER FUNCTIONS
const timer = document.getElementById('timer');
var sec = 0;
var msec = 0;
var stoptime = true;
function startTimer() {
if (stoptime == true) {
stoptime = false;
timerCycle();
}
}
function stopTimer() {
if (stoptime == false) {
stoptime = true;
timer.classList.add("time-stopped")
}
}
function timerCycle() {
if (stoptime == false) {
msec = parseInt(msec);
sec = parseInt(sec);
msec = msec + 1;
if (msec == 100) {
sec = sec + 1;
msec = 0;
}
if (msec < 10 || msec == 0) {
msec = '0' + msec;
}
if (sec < 10 || sec == 0) {
sec = '0' + sec;
}
timer.innerHTML = sec + ':' + msec;
setTimeout("timerCycle()", 10);
}
}
function resetTimer() {
timer.innerHTML = '00:00';
}
// TAB TO RESTART