-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
85 lines (75 loc) · 2.23 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
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
const minutesEl = document.getElementById("minutes");
const secondsEl = document.getElementById("seconds");
const millisecondsEl = document.getElementById("milliseconds");
const heightEl = document.getElementById("height")
const startBtn = document.getElementById("startBtn");
const stopBtn = document.getElementById("stopBtn");
const resetBtn = document.getElementById("resetBtn");
const howBtn = document.getElementById("howBtn");
let minutes = 0;
let seconds = 0;
let tens = 0;
let interval;
function updateTimerDisplay() {
millisecondsEl.textContent = tens < 10 ? "0" + tens : tens;
secondsEl.textContent = seconds < 10 ? "0" + seconds : seconds;
minutesEl.textContent = minutes < 10 ? "0" + minutes : minutes;
}
function timer() {
tens++;
if (tens > 99) {
seconds++;
tens = 0;
}
if (seconds > 59) {
minutes++;
seconds = 0;
}
updateTimerDisplay();
}
function startTimer() {
clearInterval(interval);
interval = setInterval(timer, 10);
}
function stopTimer() {
clearInterval(interval);
}
function resetTimer() {
clearInterval(interval);
minutes = 0;
seconds = 0;
tens = 0;
heightEl.textContent = "0"
updateTimerDisplay();
}
function toggleButtons(buttonToHide, buttonToShow) {
buttonToHide.classList.add("hidden");
buttonToShow.classList.remove("hidden");
}
startBtn.addEventListener("click", () => {
startTimer()
toggleButtons(startBtn, stopBtn)
});
stopBtn.addEventListener("click", () => {
stopTimer()
toggleButtons(stopBtn, resetBtn)
let totalSec = (minutes * 60) + seconds + tens / 100
heightEl.textContent = calculateHeight(totalSec)
});
resetBtn.addEventListener("click", () => {
resetTimer()
toggleButtons(resetBtn, startBtn)
});
function calculateHeight(totalSec) {
let height = 0.5 * 9.81 * (totalSec * totalSec);
return height.toFixed(2);
}
howBtn.addEventListener("click", () => {
document.getElementById("claculatorDiv").classList.toggle("hidden")
document.getElementById("howItWorksDiv").classList.toggle("hidden")
if (document.getElementById("claculatorDiv").classList.contains("hidden")) {
howBtn.textContent = "Back"
} else {
howBtn.textContent = "How it works?"
}
})