-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (37 loc) · 1.11 KB
/
script.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
function readingTime() {
const text = document.getElementById("text").value;
const wpm_input = document.getElementById("wpm").value;
if (wpm_input) {
var wpm = wpm_input;
} else {
var wpm = 183;
}
if (text) {
const words = text.trim().split(/\s+/).length;
var time = Math.ceil((words / wpm) * 60);
var hour = parseInt(time / 3600);
if (hour) {
var min = parseInt((time - hour * 3600) / 60);
var sec = time - (min * 60 + hour * 3600);
minutes = min < 10 ? "0" + min : min;
seconds = sec < 10 ? "0" + sec : sec;
if (hour > 1) {
document.getElementById(
"time"
).innerText = `${hour} hours, ${minutes}:${seconds} minutes`;
} else {
document.getElementById(
"time"
).innerText = `${hour} hour, ${minutes}:${seconds} minutes`;
}
} else {
var min = parseInt(time / 60);
var sec = time - min * 60;
minutes = min < 10 ? "0" + min : min;
seconds = sec < 10 ? "0" + sec : sec;
document.getElementById(
"time"
).innerText = `${minutes}:${seconds} minutes`;
}
}
}