Ideal Weight Calculator

Ideal Weight Calculator

body{font-family:Arial,sans-serif;background-color:#f0f0f0;margin:0;padding:0;display:flex;justify-content:center;align-items:center;min-height:100vh} .container{background-color:#fff;border:1px solid #ccc;border-radius:5px;padding:20px;text-align:center;box-shadow:0 0 10px rgba(0,0,0,0.2)} h1{margin:0 0 20px} .input-group{margin-bottom:20px;display:flex;align-items:center;justify-content:center} label{flex:1;text-align:right;margin-right:10px} input,select{flex:2;padding:5px;border-radius:5px;border:1px solid #ccc} button{background-color:#007BFF;color:#fff;padding:10px 20px;border:none;border-radius:5px;cursor:pointer} button:hover{background-color:#0056b3} #result{margin-top:20px;display:none} .hidden{display:none} document.getElementById('calculateButton').addEventListener('click', function () { calculateIdealWeight(); }); function calculateIdealWeight() { const gender = document.getElementById('gender').value; const height = parseFloat(document.getElementById('height').value); const heightUnit = document.getElementById('heightUnit').value; const weight = parseFloat(document.getElementById('weight').value); const weightUnit = document.getElementById('weightUnit').value; // Perform conversions if needed if (heightUnit === 'feetInches') { // Convert feet and inches to meters height = height * 0.3048; } if (weightUnit === 'pounds') { // Convert pounds to kilograms weight = weight * 0.453592; } // Calculate ideal weight (example formula, you can replace with your own) let idealWeight; if (gender === 'male') { idealWeight = 22.04 * Math.pow(height, 2); } else { idealWeight = 20.76 * Math.pow(height, 2); } resultDiv.style.display = 'block'; idealWeightSpan.textContent = idealWeight.toFixed(2) + ' kg'; } });

Comments