-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
82 lines (71 loc) · 2.69 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
let cronometroInterval;
let segundos = 0;
let minutos = 0;
let micro = 0;
function formatearNumero(numero) {
return (numero < 10 ? "0" : "") + numero;
}
function start_timer() {
micro++;
if (micro === 100) {
segundos++;
micro = 0;
}
if (segundos === 60) {
segundos = 0;
minutos++;
}
let minutosFormateados = formatearNumero(minutos);
let segundosFormateados = formatearNumero(segundos);
let microFormateados = formatearNumero(micro);
document.getElementById("crono").innerHTML =
minutosFormateados + ":" + segundosFormateados + ":" + microFormateados;
}
function start() {
minutos = 0;
segundos = 0;
micro = 0;
cronometroInterval = setInterval(start_timer, 10);
document.getElementById("start").innerHTML = "STOP";
document.getElementById("start").removeAttribute("onclick");
document.getElementById("start").setAttribute("onclick", "stop();");
}
function re_start() {
document.getElementById("crono").innerHTML = "00:00:00";
document
.getElementById("start")
.style.setProperty("border-radius", "1000px");
document.getElementById("start").style.setProperty("font-size", "80px");
document.getElementById("start").removeAttribute("onclick");
document.getElementById("start").setAttribute("onclick", "start();");
document.getElementById("start").style.setProperty("width", "400px");
document.getElementById("start").innerHTML = "START";
}
function stop() {
clearInterval(cronometroInterval);
tiempo = segundos + 60 * minutos + micro / 100;
height = (tiempo * tiempo * 9.80665) / 2;
height_formatted = height.toFixed(2);
average_speed = ((tiempo * 9.80665) / 2 / 1000) * 3600;
average_speed_formatted = average_speed.toFixed(2);
impact_speed = ((tiempo * 9.80665) / 1000) * 3600;
impact_speed_formatted = impact_speed.toFixed(2);
document.getElementById("start").style.setProperty("border-radius", "10px");
document.getElementById("start").style.setProperty("font-size", "25px");
document.getElementById("start").style.setProperty("width", "500px");
document.getElementById("start").innerHTML =
"<b>Time:</b> " +
tiempo.toString() +
" seconds<br>" +
"<b>Height:</b> " +
height_formatted.toString() +
" meters<br>" +
"<b>Speed:</b> " +
average_speed_formatted.toString() +
" Km/H<br>" +
"<b>Impact Speed:</b> " +
impact_speed_formatted.toString() +
" Km/H<br>Planet: Earth<br>Acceleration: 9.81 m/s²";
document.getElementById("start").removeAttribute("onclick");
document.getElementById("start").setAttribute("onclick", "re_start();");
}