Pages

Wednesday, 27 November 2024

Speed Converter Tool

Speed Converter Tool

Speed Converter Tool

body { background: linear-gradient(to right, #6a11cb, #2575fc); color: #fff; font-family: Arial, sans-serif; } h1 { font-weight: bold; text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3); } .card { background: #fff; border-radius: 10px; overflow: hidden; } .card-body { background: #f8f9fa; padding: 20px; border-radius: 10px; } #resultOutput { font-weight: bold; font-size: 1.5rem; } document.getElementById('converterForm').addEventListener('submit', function (e) { e.preventDefault(); const speedInput = parseFloat(document.getElementById('speedInput').value); const fromUnit = document.getElementById('fromUnit').value; const toUnit = document.getElementById('toUnit').value; if (isNaN(speedInput)) { alert("Please enter a valid speed."); return; } const conversionRates = { kmh: { kmh: 1, mph: 0.621371, ms: 0.277778 }, mph: { kmh: 1.60934, mph: 1, ms: 0.44704 }, ms: { kmh: 3.6, mph: 2.23694, ms: 1 } }; const convertedSpeed = (speedInput * conversionRates[fromUnit][toUnit]).toFixed(2); document.getElementById('resultOutput').textContent = `${speedInput} ${fromUnit.toUpperCase()} is equal to ${convertedSpeed} ${toUnit.toUpperCase()}`; });