This commit is contained in:
Philippe Torrel
2026-08-19 11:41:58 +02:00
parent c6d9611e81
commit ae9b04f27f
111 changed files with 3878 additions and 24 deletions

View File

@@ -1,17 +1,47 @@
'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(); // Standardverhalten unterbinden
const celsius = Number(DOM.celsiusInput.value);
// === XHR/FETCH ========
// falsche Verneinung
if (isNaN(celsius)) {
alert('Please enter a valid number');
return;
}
// === FUNCTIONS ========
const fahrenheit = convertToFahrenheit(celsius);
displayResult(fahrenheit);
DOM.temperatureForm.reset();
}
// ===== FUNCTIONS =====
function convertToFahrenheit(celsius) {
if (typeof celsius !== 'number') return NaN;
return (celsius * 9) / 5 + 32;
}
function displayResult(result) {
DOM.result.textContent = result.toFixed(2);
}
// ===== CALL INIT =====
init();
})();