-
Notifications
You must be signed in to change notification settings - Fork 0
/
durasi-aki.html
111 lines (93 loc) · 4.24 KB
/
durasi-aki.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js" integrity="sha256-f6DVw/U4x2+HjgEqw5BZf67Kq/5vudRZuRkljnbF344=" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-sm h-100 mt-5">
<div class="row h-100 justify-content-center align-items-center">
<div class="card" >
<div class="card-body">
<h5 class="card-title">Menghitung Durasi Ketahanan Baterai</h5>
<form class="col-12">
<div class="form-group">
<label for="batV" >Baterai V</label>
<input class="form-control" type="number" id="batV" placeholder="12">
</div>
<div class="form-group">
<label for="batAh" >Baterai Ah</label>
<input class="form-control" type="number" id="batAh" placeholder="100">
</div>
<div class="form-group">
<label for="beban" >Beban W</label>
<input class="form-control" type="number" id="beban" placeholder="50">
</div>
<div class="form-group">
<label for="batCap" >Kapasitas Baterai Yang Digunakan %</label>
<input class="form-control" type="number" id="batCap" max="100" placeholder="80">
</div>
<div class="form-group">
<label for="hasil" >Durasi</label>
<input class="form-control" type="text" id="hasil" readonly>
</div>
<div class="form-group mt-3">
<button type="button" class="btn btn-primary" id="hitung">Hitung</button>
</div>
</form>
</div>
<div class="p-3">
<i style="float: right;">Rabata Media</i>
</div>
</div>
</div>
</div>
<script>
function hitung() {
var batV = $("#batV").val();
var batAh = $("#batAh").val();
var batCap = $("#batCap").val();
var beban = $("#beban").val();
var batTot = (batV * batAh);
var batUse = (batTot * batCap/100);
var hasil = (batUse / beban);
if(isNaN(hasil)){
hasil = 0;
}
console.log(hasil)
$("#hasil").val(convert(hasil));
}
function convert(decimalTimeString){
// https://stackoverflow.com/questions/35460303/how-to-convert-decimal-hour-value-to-hhmmss
var decimalTime = parseFloat(decimalTimeString);
decimalTime = decimalTime * 60 * 60;
var hours = Math.floor((decimalTime / (60 * 60)));
decimalTime = decimalTime - (hours * 60 * 60);
var minutes = Math.floor((decimalTime / 60));
decimalTime = decimalTime - (minutes * 60);
var seconds = Math.round(decimalTime);
if(hours < 10)
{
hours = "0" + hours;
}
if(minutes < 10)
{
minutes = "0" + minutes;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
return ("" + hours + ":" + minutes + ":" + seconds);
}
$("#hitung").click(function(){
hitung()
}
)
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>