This commit is contained in:
Philippe Torrel
2026-11-03 11:40:59 +01:00
parent a885cd9550
commit baf557f666
17 changed files with 1158 additions and 19 deletions
@@ -1,17 +1,45 @@
'use strict';
(() => {
// === DOM & VARS =======
const DOM = {};
// ===== DOM =====
const DOM = {
temperatureForm: document.querySelector('#temperatureForm'),
celsiusInput: document.querySelector('#celsius'),
result: document.querySelector('#result'),
};
// === INIT =============
const init = () => {};
// ===== INIT =====
const init = () => {
DOM.temperatureForm.addEventListener('submit', handleFormSubmit);
};
// === EVENTHANDLER =====
// ===== EVENT HANDLERS =====
function handleFormSubmit(e) {
e.preventDefault();
const celsius = Number(DOM.celsiusInput.value);
// === XHR/FETCH ========
if (isNaN(celsius)) {
alert('Please enter a valid number');
return;
}
const fahrenheit = convertToFahrenheit(celsius);
// === FUNCTIONS ========
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();
})();