This commit is contained in:
Philippe Torrel
2026-08-18 14:27:34 +02:00
parent c7d26e1cd9
commit c6d9611e81
35 changed files with 1852 additions and 130 deletions

View File

@@ -0,0 +1,17 @@
'use strict';
(() => {
// === DOM & VARS =======
const DOM = {};
// === INIT =============
const init = () => {};
// === EVENTHANDLER =====
// === XHR/FETCH ========
// === FUNCTIONS ========
init();
})();

View File

@@ -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();
})();