-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
122 lines (103 loc) · 2.87 KB
/
index.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
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calorie Status</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
.container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
margin-bottom: 20px;
}
.counter {
font-size: 48px;
margin-bottom: 20px;
}
#deficit-count {
font-size: 24px;
}
button {
margin: 5px;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
#reset-button {
background-color: #ff6347;
color: white;
}
#exercise-button {
background-color: #4caf50;
color: white;
}
#eat-button {
background-color: #2196f3;
color: white;
}
</style>
</head>
<body>
<div class="container">
<h1>Calorie Status</h1>
<div class="counter">
<p id="calorie-count">0</p>
<p id="deficit-count">0</p>
</div>
<button id="reset-button">Reset</button>
<button id="exercise-button">-100 kcal</button>
<button id="eat-button">+100 kcal</button>
</div>
<script type="text/javascript">
// user configuration ------
// these will count our calories burned at rest
let calorieCount = 0;
const hourlyCalorieBurn = 2000 / 24.0; // burned per hour
// goal is to lose 500 kcal/day (i.e. ~1 lb/week)
let desiredDeficitCount = 0;
const hourlyCalorieTargetDeficit = 500 / 24.0;
// --------------------------
let lastUpdateTime = Date.now();
function updateCalorieCount() {
const currentTime = Date.now();
const elapsedHours = (currentTime - lastUpdateTime) / (1000 * 60 * 60);
calorieCount -= elapsedHours * hourlyCalorieBurn;
desiredDeficitCount -= elapsedHours * hourlyCalorieTargetDeficit;
lastUpdateTime = currentTime;
document.getElementById('calorie-count').innerText = calorieCount.toFixed(2);
document.getElementById('deficit-count').innerText = "GOAL: " + desiredDeficitCount.toFixed(2);
let color = calorieCount < desiredDeficitCount ? 'green' : 'red'; // green if met, red otherwise
document.getElementById('deficit-count').style.color = color;
}
document.getElementById('reset-button').addEventListener('click', () => {
calorieCount = 0;
desiredDeficitCount = 0; // reset the goal counter as well
lastUpdateTime = Date.now();
});
document.getElementById('exercise-button').addEventListener('click', () => {
updateCalorieCount();
calorieCount -= 100;
});
document.getElementById('eat-button').addEventListener('click', () => {
updateCalorieCount();
calorieCount += 100;
});
setInterval(updateCalorieCount, 500); // update counter every 500ms
</script>
</body>
</html>