Convert between various units (length, weight, volume, temperature, time). Select Conversion Type: Length Weight Volume Temperature Time Enter value to convert: Convert from: Convert to: Convert // Conversion rates for different types const conversionRates = { length: { meters: 1, kilometers: 0.001, miles: 0.000621371, feet: 3.28084 }, weight: { kilograms: 1, grams: 1000, pounds: 2.20462, ounces: 35.274 }, volume: { liters: 1, milliliters: 1000, gallons: 0.264172, cups: 4.22675 }, temperature: { celsius: { toFahrenheit: (c) => (c * 9/5) + 32, toKelvin: (c) => c + 273.15 }, fahrenheit: { toCelsius: (f) => (f - 32) * 5/9, toKelvin: (f) => ((f - 32) * 5/9) + 273.15 }, kelvin: { toCelsius: (k) => k - 273.15, toFahrenheit: (k) => (k - 273.15) * 9/5 + 32 } }, time: { seconds: 1, minutes: 1 / 60, hours: 1 / 3600, days: 1 / 86400 } }; // Populates the dropdown units based on selected conversion type function populateUnits() { const conversionType = document.getElementById('conversionType').value; const fromUnit = document.getElementById('fromUnit'); const toUnit = document.getElementById('toUnit'); // Clear existing options fromUnit.innerHTML = ''; toUnit.innerHTML = ''; let units = Object.keys(conversionRates[conversionType]); // For temperature conversion, use different logic if (conversionType === 'temperature') { units = ['celsius', 'fahrenheit', 'kelvin']; } units.forEach(unit => { const optionFrom = document.createElement('option'); optionFrom.value = unit; optionFrom.textContent = capitalize(unit); fromUnit.appendChild(optionFrom); const optionTo = document.createElement('option'); optionTo.value = unit; optionTo.textContent = capitalize(unit); toUnit.appendChild(optionTo); }); } function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } function validateInput(value) { const valueError = document.getElementById('valueError'); if (isNaN(value) || value