Example output
HTML (index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<script src="script.js" defer></script>
<title>Calories Burnt Calculator</title>
</head>
<body>
<div class="calculator">
<h1>Calories Burnt Calculator</h1>
<label for="activity">Select Activity:</label>
<select id="activity">
<option value="running">Running</option>
<option value="cycling">Cycling</option>
<!-- Add more activity options here -->
</select>
<label for="duration">Duration (minutes):</label>
<input type="number" id="duration" min="1">
<button id="calculate">Calculate</button>
<div id="result"></div>
</div>
</body>
</html>
CSS (styles.css):
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.calculator {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
margin-top: 0;
color: #333;
}
label {
display: block;
margin-top: 10px;
}
select,
input {
width: 100%;
padding: 10px;
margin: 5px 0;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
background-color: #007bff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
#result {
margin-top: 20px;
font-size: 18px;
}
JavaScript (script.js):
document.addEventListener("DOMContentLoaded", function () {
const calculateButton = document.getElementById("calculate");
const activitySelect = document.getElementById("activity");
const durationInput = document.getElementById("duration");
const resultDiv = document.getElementById("result");
calculateButton.addEventListener("click", function () {
const activity = activitySelect.value;
const duration = parseFloat(durationInput.value);
let caloriesPerMinute;
switch (activity) {
case "running":
caloriesPerMinute = 10;
break;
case "cycling":
caloriesPerMinute = 8;
break;
// Add more cases for other activities
default:
caloriesPerMinute = 5;
}
const totalCaloriesBurnt = caloriesPerMinute * duration;
resultDiv.textContent = `Calories Burnt: ${totalCaloriesBurnt.toFixed(2)}`;
});
});