204°C to °F Conversion Calculator
// Handle Celsius input celsiusInput.addEventListener('input', function() { const inputVal = this.value;
if (inputVal === '' || isNaN(inputVal)) { fahrenheitInput.value = ''; resultDisplay.textContent = 'Please enter a valid temperature'; return; }
const celsius = parseFloat(inputVal); const fahrenheit = celsiusToFahrenheit(celsius);
// Update immediately fahrenheitInput.value = fahrenheit; updateResultDisplay(celsius, fahrenheit);
// Visual feedback animateResult(); });
// Handle Fahrenheit input fahrenheitInput.addEventListener('input', function() { const inputVal = this.value;
if (inputVal === '' || isNaN(inputVal)) { celsiusInput.value = ''; resultDisplay.textContent = 'Please enter a valid temperature'; return; }
const fahrenheit = parseFloat(inputVal); const celsius = fahrenheitToCelsius(fahrenheit);
// Update immediately celsiusInput.value = formatTemperature(celsius); updateResultDisplay(celsius, fahrenheit);
// Visual feedback animateResult(); });
function celsiusToFahrenheit(celsius) { const result = (celsius * 9/5) + 32; return formatNumber(result); }
function fahrenheitToCelsius(fahrenheit) { const result = (fahrenheit - 32) * 5/9; return formatNumber(result); }
function formatNumber(num) { return parseFloat(num.toFixed(2)); }
function formatTemperature(temp) { return Number.isInteger(parseFloat(temp)) ? parseInt(temp) : parseFloat(temp).toFixed(1); }
function updateResultDisplay(celsius, fahrenheit) { const formattedCelsius = formatTemperature(celsius); const formattedFahrenheit = formatNumber(fahrenheit); resultDisplay.textContent = `${formattedCelsius}°C = ${formattedFahrenheit}°F`; }
function animateResult() { resultDisplay.classList.add('updated'); setTimeout(() => resultDisplay.classList.remove('updated'), 300); } });