Pages

Saturday, 21 December 2024

Power Converter Tool



Power Converter Tool

Power Converter Tool

* { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Arial', sans-serif; background: linear-gradient(135deg, #6a11cb, #2575fc); color: white; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background: rgba(0, 0, 0, 0.7); padding: 20px; border-radius: 10px; width: 90%; max-width: 400px; text-align: center; } h1 { font-size: 24px; margin-bottom: 20px; } .input-group { margin-bottom: 15px; } label { display: block; margin-bottom: 5px; font-weight: bold; } input, select { width: 100%; padding: 10px; border: none; border-radius: 5px; } button { background: #4caf50; color: white; padding: 10px 15px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; transition: background 0.3s; } button:hover { background: #45a049; } #result { margin-top: 20px; font-size: 18px; font-weight: bold; } document.getElementById('convertBtn').addEventListener('click', function () { const inputValue = parseFloat(document.getElementById('inputValue').value); const inputUnit = document.getElementById('inputUnit').value; const outputUnit = document.getElementById('outputUnit').value; if (isNaN(inputValue)) { document.getElementById('result').innerText = 'Please enter a valid number.'; return; } const conversionRates = { watts: { watts: 1, kilowatts: 0.001, horsepower: 0.00134102, btu: 3.41214, }, kilowatts: { watts: 1000, kilowatts: 1, horsepower: 1.34102, btu: 3412.14, }, horsepower: { watts: 745.7, kilowatts: 0.7457, horsepower: 1, btu: 2544.43, }, btu: { watts: 0.293071, kilowatts: 0.000293071, horsepower: 0.000393014, btu: 1, }, }; const convertedValue = inputValue * conversionRates[inputUnit][outputUnit]; document.getElementById('result').innerText = `Converted Value: ${convertedValue.toFixed(2)} ${outputUnit}`; });