-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
178 lines (142 loc) · 5.65 KB
/
test.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.main {
width: 100%;
height: 100vh;
position: relative;
background-color: blanchedalmond;
}
.center {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
font-weight: bold;
font-size: 1.3cm;
}
hr {
height: 1cm;
background-color: rgb(112, 4, 40);
/* color: rgb(112, 4, 40); */
}
textarea {
border: rgb(0, 0, 0) solid;
border-width: 0.2cm;
border-style: double;
background-color: rgb(112, 4, 40);
font-size: 0.7cm;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
color: white;
}
.button {
background-color: grey;
color: black;
padding: 20px 30px;
border-radius: 30px;
border-width: 0.2cm;
border-color: black;
font-size: 0.8cm;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}
</style>
</head>
<body>
<header>
</header>
<hr>
<div class="main">
<div class="center">
<h1>TYPING SPEED TESTER</h1>
<br>
<textarea id="words" cols="100" rows="10" placeholder="Enter text here :)"></textarea>
<br><br><br>
<h2 id="msg"></h2>
<br><br>
<h2 id="msg2"></h2>
<br><br><br>
<button id="button" class="button">START</button>
</div>
</div>
<script>
const testcases = ["Lotus is the national flower of both India and Vietnam. Interestingly, it is the Lotus pink flowers that are a national symbol.", "Peacock is one of the most beautiful creatures of the earth, which is feathered. Peacock is a blue colored bird, and its feathers are blue, green, and golden.", "Hockey is an outdoor game played by two opposing teams of 11 players each who use sticks curved at the striking end to hit a small, hard ball into their opponent's goal.", "Pumpkin is a plump, nutritious orange vegetable, and a highly nutrient dense food. It is low in calories.", "Tiger is the biggest wild animal in the cat family. It is one of the strongest animals of the jungle. Tiger is a carnivorous animal.", "The song Jana-gana-mana, composed originally in Bangla by Rabindranath Tagore.", "The national song of India, Vande Mataram is a collection of six total stanzas. The original poem was written in Bengali as Bande Mataram."];
const msg = document.getElementById('msg');
const msg2 = document.getElementById('msg2');
const words = document.getElementById('words');
const button = document.getElementById('button');
words.disabled = true;
let startTime, endTime;
const wordCounter = (str) => {
let response = (str.split(" ")).length;
const a1 = str.split(" ");
if (a1[0] == "") {
return 0;
}
return response;
}
const compareWords = (str1, str2) => {
const a1 = str1.split(" ");
const a2 = str2.split(" ");
let counter = 0;
// a1.forEach(function(item, index) {
// if (item == a2[index]) {
// counter++;
// }
// })
for (i = 0; i < a1.length; i++) {
if (a1[i] == a2[i]) {
counter++;
}
}
let accuracy = counter / a1.length * 100;
return accuracy;
}
const startCounting = () => {
let randomNumber = Math.floor(Math.random() * (testcases.length));
msg.innerText = testcases[randomNumber];
let date = new Date();
startTime = date.getTime();
button.innerText = "DONE";
}
const endCounting = () => {
let date = new Date();
endTime = date.getTime();
let totalTime = (endTime - startTime) / 1000;
let totalString = words.value;
let wordCount = wordCounter(totalString);
let speed = wordCount / totalTime;
let finalMsg = "Your speed is " + speed + " words per second";
let finalMsg2 = "ACCURACY: " + compareWords(msg.innerText, totalString) + "%";
msg.innerText = finalMsg;
msg2.innerText = finalMsg2;
}
button.addEventListener('click', function() {
if (this.innerText == "START") {
words.disabled = false;
words.value = '';
startCounting();
msg2.innerText = "";
} else if (this.innerText == "DONE") {
words.disabled = true;
button.innerText = "START";
endCounting();
}
})
</script>
<hr>
</body>
</html>