Calorie Calculator /* Set the body's font size and background color */ body { font-size: 14px; background-color: #f1f1f1; } /* Style the form elements */ #calorie-form input[type="number"], #calorie-form select { width: 60px; padding: 5px; border: 1px solid #ccc; border-radius: 4px; } #calorie-form label { margin-right: 10px; } #calorie-form input[type="submit"] { background-color: #4CAF50; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; } #calorie-form input[type="submit"]:hover { background-color: #45a049; } Calorie Calculator Weight: kg lbs Height: cm ft Age: Gender: Male Female Activity Level: Sedentary Light Moderate Active Very Active function calculateCalories() { // Get the form element var form = document.getElementById('calorie-form'); // Get the weight, height, age, gender, and activity level from the form var weight = form.elements.weight.value; var weightUnit = form.elements['weight-unit'].value; var height = form.elements.height.value; var heightUnit = form.elements['height-unit'].value; var age = form.elements.age.value; var gender = form.elements.gender.value; var activityLevel = form.elements['activity-level'].value; if (weightUnit === 'lbs') { weight = weight * 0.45359237; } if (heightUnit === 'ft') { height = height * 30.48; } // Calculate the basal metabolic rate (BMR) based on the Harris-Benedict equation var BMR; if (gender === 'male') { BMR = 66 + (13.7 * weight) + (5 * height) - (6.8 * age); } else { BMR = 655 + (9.6 * weight) + (1.8 * height) - (4.7 * age); } // Calculate the number of calories needed based on the BMR and the activity level var calories; switch (activityLevel) { case 'sedentary': calories = BMR * 1.2; break; case 'light': calories = BMR * 1.375; break; case 'moderate': calories = BMR * 1.55; break; case 'active': calories = BMR * 1.725; break; case 'very-active': calories = BMR * 1.9; break; } // Display the number of calories needed alert(`You need approximately ${calories.toFixed(0)} calories per day.`); } // Attach the calculateCalories function to the form's submit event var form = document.getElementById('calorie-form'); form.addEventListener('submit', calculateCalories);