This commit is contained in:
Philippe Torrel
2026-11-02 13:02:29 +01:00
parent 50c1e85931
commit b21be6c1d1
19 changed files with 795 additions and 0 deletions
@@ -0,0 +1,45 @@
'use strict';
(() => {
// ===== DOM =====
const DOM = {
temperatureForm: document.querySelector('#temperatureForm'),
celsiusInput: document.querySelector('#celsius'),
result: document.querySelector('#result'),
};
// ===== INIT =====
const init = () => {
DOM.temperatureForm.addEventListener('submit', handleFormSubmit);
};
// ===== EVENT HANDLERS =====
function handleFormSubmit(e) {
const celsius = DOM.celsiusInput.value;
if (!isNaN(celsius)) {
alert('Please enter a valid number');
return;
}
const fahrenheit = convertToFahrenheit(celsius);
displayResult(fahrenheit);
DOM.temperatureForm.reset();
}
// ===== FUNCTIONS =====
function convertToFahrenheit(celsius) {
if (typeof celsius === 'string') return 0;
return (celsius * 9) / 5 + 32;
}
function displayResult(result) {
DOM.result.textContent = result.toFixed(2);
}
// ===== CALL INIT =====
init();
})();