-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.html
58 lines (47 loc) · 1.96 KB
/
calculator.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Health Schedule Website</title>
<link rel="stylesheet" href="home.css">
</head>
<body>
<h1>Calculate!</h1>
<label for="exercise">Choose an exercise:</label>
<select id="exercise">
<option value="600">Running</option>
<option value="500">Cycling</option>
<option value="700">Swimming</option>
<option value="300">Walking</option>
<option value="200">Yoga</option>
</select>
<br><br>
<label for="weight">Enter the weight you want to lose (kg):</label>
<input type="number" id="weight" step="0.1">
<br><br>
<label for="days">Enter the target period (days):</label>
<input type="number" id="days">
<br><br>
<button onclick="calculateCalories()">Calculate</button>
<h2 id="result"></h2>
<a href="home.html">
<button>Home</button>
</a>
<script>
function calculateCalories() {
const exercise = document.getElementById("exercise").value; // Calories per hour
const weight = parseFloat(document.getElementById("weight").value); // Weight to lose
const days = parseInt(document.getElementById("days").value); // Target period
if (isNaN(weight) || isNaN(days) || days <= 0) { // checking whether weight or days is a valid number
document.getElementById("result").innerText = "Please enter valid inputs.";
return;
}
const caloriesPerKg = 7700;
const totalCalories = weight * caloriesPerKg; // Total calories needed
const dailyCalories = totalCalories / days; // Daily calorie requirement
const hoursPerDay = dailyCalories / exercise; // Hours of exercise per day
document.getElementById("result").innerText =
`To lose ${weight} kg in ${days} days, you need to exercise for ${hoursPerDay.toFixed(2)} hours per day.`;
}
</script>
</body>
</html>