-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstacks.html
More file actions
98 lines (73 loc) · 1.78 KB
/
stacks.html
File metadata and controls
98 lines (73 loc) · 1.78 KB
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
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width,minimum-scale=1" />
<title>Stacks</title>
<style>
body {
font-family: arial;
background: #4E598C;
display: flex;
flex-direction: column;
}
body > * {
margin: 0 auto;
padding-bottom: 10px;
}
.money, #time {
color: #F9C784;
font-size: 50px;
}
button {
font-size: 30px;
box-shadow: 2px 2px 10px #000;
line-height: 30px;
padding: 5px;
background: #FF8C42;
color: white;
border: 0;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="money">
$
<span id="amount">0.00</span>
CAD
</div>
<div id="time">
0:00:00
</div>
<button id="btn" onclick="startTimer()">Start</start>
</body>
<script>
let startTime = null;
let interval;
const usdPerHour = 750;
const cadPerHour = 1.34 * 750;
const cadPerMillisecond = cadPerHour / 3600_000;
function startTimer() {
startTime = Date.now();
interval = setInterval(tick, 10);
document.getElementById('btn').style.display = 'none';
}
function tick() {
const timePassed = Date.now() - startTime;
if (timePassed >= 3600_000) {
setValues(3600_000);
clearInterval(interval);
return;
}
setValues(timePassed);
}
function setValues(timePassed) {
let timeStr;
if (timePassed === 3600_000) {
timeStr = '1:00:00';
} else {
timeStr = '0:' + Math.floor(timePassed / 60_000).toString().padStart(2, '0') + ':' + Math.floor((timePassed / 1000) % 60).toString().padStart(2, '0');
}
document.getElementById('amount').innerText = (timePassed * cadPerMillisecond).toFixed(2);
document.getElementById('time').innerText = timeStr;
}
</script>